Skip to content

Commit

Permalink
Merge pull request #10 from trparky/dev
Browse files Browse the repository at this point in the history
Merged in changes from the dev branch
  • Loading branch information
trparky authored Jun 25, 2023
2 parents 22178e4 + e4a5b87 commit 1a4655a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 43 deletions.
19 changes: 3 additions & 16 deletions Hasher/Form1.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Hasher/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ that the two files are different. However, if you want to compute the hashes any
<metadata name="textHashContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>468, 19</value>
</metadata>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>180, 18</value>
</metadata>
</root>
16 changes: 9 additions & 7 deletions Hasher/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ Public Class Form1
For Each item As MyListViewItem In listFiles.Items
If Not String.IsNullOrWhiteSpace(item.Hash) Then
strFile = item.FileName
If chkSaveChecksumFilesWithRelativePaths.Checked Then strFile = strFile.CaseInsensitiveReplace(folderOfChecksumFile, "", StringComparison.OrdinalIgnoreCase)
If chkSaveChecksumFilesWithRelativePaths.Checked Then strFile = strFile.Replace(folderOfChecksumFile, "", StringComparison.OrdinalIgnoreCase)
stringBuilder.AppendLine($"{GetDataFromAllTheHashes(checksumType, item.AllTheHashes)} *{strFile}")
End If
Next
Expand Down Expand Up @@ -861,7 +861,7 @@ Public Class Form1

If strReceivedMessage.StartsWith("--comparefile=", StringComparison.OrdinalIgnoreCase) Then
MyInvoke(Sub()
Dim strFilePathToBeCompared As String = strReceivedMessage.CaseInsensitiveReplace("--comparefile=", "", StringComparison.OrdinalIgnoreCase)
Dim strFilePathToBeCompared As String = strReceivedMessage.Replace("--comparefile=", "", StringComparison.OrdinalIgnoreCase)

If String.IsNullOrWhiteSpace(txtFile1.Text) And String.IsNullOrWhiteSpace(txtFile2.Text) Then
txtFile1.Text = strFilePathToBeCompared
Expand All @@ -875,7 +875,7 @@ Public Class Form1
If Not String.IsNullOrWhiteSpace(txtFile1.Text) AndAlso Not String.IsNullOrWhiteSpace(txtFile2.Text) Then btnCompareFiles.PerformClick()
End Sub)
ElseIf strReceivedMessage.StartsWith("--addfile=", StringComparison.OrdinalIgnoreCase) Then
AddFileOrDirectoryToHashFileList(strReceivedMessage.CaseInsensitiveReplace("--addfile=", "", StringComparison.OrdinalIgnoreCase))
AddFileOrDirectoryToHashFileList(strReceivedMessage.Replace("--addfile=", "", StringComparison.OrdinalIgnoreCase))
End If

namedPipeServer.Dispose()
Expand All @@ -901,11 +901,11 @@ Public Class Form1
' so, this instance of the program will continue operating as the host of the named pipe server.
If commandLineArgument.StartsWith("--addfile=", StringComparison.OrdinalIgnoreCase) Then
' We now have to strip off what we don't need.
commandLineArgument = commandLineArgument.CaseInsensitiveReplace("--addfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
commandLineArgument = commandLineArgument.Replace("--addfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
AddFileOrDirectoryToHashFileList(commandLineArgument)
ElseIf commandLineArgument.StartsWith("--comparefile=", StringComparison.OrdinalIgnoreCase) Then
' We now have to strip off what we don't need.
commandLineArgument = commandLineArgument.CaseInsensitiveReplace("--comparefile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
commandLineArgument = commandLineArgument.Replace("--comparefile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
txtFile1.Text = commandLineArgument
End If
Else
Expand All @@ -917,7 +917,7 @@ Public Class Form1
Process.GetCurrentProcess.Kill() ' This terminates the process.
End If
ElseIf commandLineArgument.StartsWith("--hashfile=", StringComparison.OrdinalIgnoreCase) Then
commandLineArgument = commandLineArgument.CaseInsensitiveReplace("--hashfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
commandLineArgument = commandLineArgument.Replace("--hashfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")

If IO.File.Exists(commandLineArgument) Then
TabControl1.SelectTab(TabNumberVerifySavedHashesTab)
Expand All @@ -926,7 +926,7 @@ Public Class Form1
ProcessExistingHashFile(commandLineArgument)
End If
ElseIf commandLineArgument.StartsWith("--knownhashfile=", StringComparison.OrdinalIgnoreCase) Then
commandLineArgument = commandLineArgument.CaseInsensitiveReplace("--knownhashfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
commandLineArgument = commandLineArgument.Replace("--knownhashfile=", "", StringComparison.OrdinalIgnoreCase).Replace(Chr(34), "")
TabControl1.SelectTab(TabNumberCompareFileAgainstKnownHashTab)
txtFileForKnownHash.Text = commandLineArgument
txtKnownHash.Select()
Expand Down Expand Up @@ -963,6 +963,7 @@ Public Class Form1
chkDisplayHashesInUpperCase.Checked = My.Settings.boolDisplayHashesInUpperCase
chkUseCommasInNumbers.Checked = My.Settings.boolUseCommasInNumbers
chkCheckForUpdates.Checked = My.Settings.boolCheckForUpdates
btnCheckForUpdates.Visible = Not chkCheckForUpdates.Checked
chkAutoAddExtension.Checked = My.Settings.boolAutoAddExtension
chkDisplayValidChecksumString.Checked = My.Settings.boolDisplayValidChecksumString
chkOpenInExplorer.Checked = My.Settings.boolOpenInExplorer
Expand Down Expand Up @@ -2634,6 +2635,7 @@ Public Class Form1

Private Sub ChkCheckForUpdates_Click(sender As Object, e As EventArgs) Handles chkCheckForUpdates.Click
My.Settings.boolCheckForUpdates = chkCheckForUpdates.Checked
btnCheckForUpdates.Visible = Not chkCheckForUpdates.Checked
End Sub

Private Sub ChkAutoAddExtension_Click(sender As Object, e As EventArgs) Handles chkAutoAddExtension.Click
Expand Down
2 changes: 1 addition & 1 deletion Hasher/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Imports System.Runtime.InteropServices
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("7.1.1.0")>
<Assembly: AssemblyFileVersion("7.1.2.0")>
17 changes: 3 additions & 14 deletions Hasher/Program Modules/Check for Update.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace checkForUpdates
Dim currentProcessFileName As String = New FileInfo(Application.ExecutablePath).Name

If currentProcessFileName.CaseInsensitiveContains(".new.exe") Then
Dim mainEXEName As String = currentProcessFileName.CaseInsensitiveReplace(".new.exe", "", StringComparison.OrdinalIgnoreCase)
Dim mainEXEName As String = currentProcessFileName.Replace(".new.exe", "", StringComparison.OrdinalIgnoreCase)

SearchForProcessAndKillIt(mainEXEName, False)

Expand Down Expand Up @@ -251,18 +251,7 @@ Namespace checkForUpdates
Private Sub DownloadAndPerformUpdate()
Dim newExecutableName As String = $"{New FileInfo(Application.ExecutablePath).Name}.new.exe"

' We have to do this stuff on the thread that the form belongs to or we will get an error.
windowObject.Invoke(Sub()
windowObject.lblDownloadNotification.Visible = True
End Sub)

Dim httpHelper As HttpHelper = CreateNewHTTPHelperObject()
httpHelper.SetDownloadStatusUpdateRoutine = Function(downloadStatusDetails As DownloadStatusDetails)
windowObject.Invoke(Sub()
windowObject.lblDownloadNotification.Text = $"{downloadStatusDetails.PercentageDownloaded}% Downloaded."
End Sub)
Return Nothing
End Function

Using memoryStream As New MemoryStream()
If Not httpHelper.DownloadFile(programZipFileURL, memoryStream, False) Then
Expand Down Expand Up @@ -300,7 +289,7 @@ Namespace checkForUpdates
Private Shared Function CreateHTTPUserAgentHeaderString() As String
Dim versionInfo As String() = Application.ProductVersion.Split(".")
Dim versionString As String = $"{versionInfo(0)}.{versionInfo(1)} Build {versionInfo(2)}"
Return $"Hasher version {versionString} on {GetFullOSVersionString()}"
Return $"{strProgramName} version {versionString} on {GetFullOSVersionString()}"
End Function

Private Shared Function GetFullOSVersionString() As String
Expand Down Expand Up @@ -366,7 +355,7 @@ Namespace checkForUpdates
Dim response As ProcessUpdateXMLResponse = ProcessUpdateXMLData(xmlData, remoteVersion, remoteBuild)

If response = ProcessUpdateXMLResponse.newVersion Then
If BackgroundThreadMessageBox($"An update to Hasher (version {remoteVersion} Build {remoteBuild}) is available to be downloaded, do you want to download and update to this new version?", strMessageBoxTitleText) = MsgBoxResult.Yes Then
If BackgroundThreadMessageBox($"An update to {strProgramName} (version {remoteVersion} Build {remoteBuild}) is available to be downloaded, do you want to download and update to this new version?", strMessageBoxTitleText) = MsgBoxResult.Yes Then
DownloadAndPerformUpdate()
Else
windowObject.Invoke(Sub() MsgBox("The update will not be downloaded.", MsgBoxStyle.Information, strMessageBoxTitleText))
Expand Down
10 changes: 5 additions & 5 deletions Hasher/Program Modules/StringExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Module StringExtensions
Return haystack.IndexOf(needle, StringComparison.OrdinalIgnoreCase) <> -1
End Function

'''<summary>Returns a New String In which all occurrences Of a specified String In the current instance are replaced With another specified string according the type of search to use for the specified string.</summary>
''' <param name="source">The string performing the replace method.</param>
''' <param name="strReplace">The string to be replaced.</param>
''' <param name="strReplaceWith">The string replace all occurrences of <paramref name="strReplaceWith"/>.
'''<summary>Works similar to the original String Replacement function but with a potential case-insensitive match capability.</summary>
''' <param name="source">The source String.</param>
''' <param name="strReplace">The String to be replaced.</param>
''' <param name="strReplaceWith">The String that will replace all occurrences of <paramref name="strReplaceWith"/>.
''' If value Is equal to <c>null</c>, than all occurrences of <paramref name="strReplace"/> will be removed from the <paramref name="source"/>.</param>
''' <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
''' <returns>A string that Is equivalent to the current string except that all instances of <paramref name="strReplace"/> are replaced with <paramref name="strReplaceWith"/>.
''' If <paramref name="strReplace"/> Is Not found in the current instance, the method returns the current instance unchanged.</returns>
<Extension()>
Public Function CaseInsensitiveReplace(source As String, strReplace As String, strReplaceWith As String, comparisonType As StringComparison) As String
Public Function Replace(source As String, strReplace As String, strReplaceWith As String, comparisonType As StringComparison) As String
If String.IsNullOrWhiteSpace(source) Then Throw New ArgumentNullException(NameOf(source))
If source.Length = 0 Then Return source
If String.IsNullOrWhiteSpace(strReplace) Then Throw New ArgumentNullException(NameOf(strReplace))
Expand Down

0 comments on commit 1a4655a

Please sign in to comment.