\[CLOSED\] 1000 DogeCoin + 10 FTC for Assistance w/VS Express 12 (n00b aLeRt)
-
First, you’ll want to add a progress bar to your form (NWOInstallerForm.vb) so the user knows something is actually going on while the search is working. You can either set the progress bar style to marquee using the properties window or have it handled in code. So before the form load event handler (NWOInstallerForm_Load) paste
[code]
‘’’
‘’’ Holds the value of the file location if it is found, otherwise it’s empty.
‘’’
Private searchResult As String‘’’
‘’’ Recursively searches the path specified for the file specified.
‘’’
‘’’ The path, including filename, of the file if the file is found. Otherwise an empty string.
Private Function DirectorySearch(path As String, filename As String) As String
’ rather than deal with ACL parsing we simply handle the unauthorized access exception
Try
’ check if the path is a reparse point, if it’s not we continue
’ this check is put in so we don’t have to 1) deal with the reparse point targeting and b)
’ deal with excess recursion.
If (IO.File.GetAttributes(path) And IO.FileAttributes.ReparsePoint) <> IO.FileAttributes.ReparsePoint Then
’ as with authorization, there’s a chance the search parameters may end up overflowing –
’ if the path + filename is too long we get an exception. we handle this exception
’ the same way as with the unauthorized access exception: we eat it.
Try
’ check the directory files to see if there’s a matching filename, if there is
’ return the filename.
For Each file As String In IO.Directory.GetFiles(path, filename)
Return file
Next
Catch exception As IO.PathTooLongException
’ munch munch
End Try’ since the directory did not have a filename that matches the one specified
’ continue recursing through the tree
For Each folder As String In IO.Directory.GetDirectories(path)
Dim fileSearch As String = DirectorySearch(folder, filename)
If fileSearch.Length > 0 Then
Return fileSearch
End If
Next
End If
Catch exception As UnauthorizedAccessException
’ munch munch and blegh
Return “”
End Try
Return “”
End Function‘’’
‘’’ Searches the drives on the system for a specific file – if localStorageOnly is set to false this includes all drives rather than simply fixed drives.
‘’’
‘’’ Returns a string which is either the path for the file, including filename, or empty if the file is not found
Private Function DriveSearch(filename As String, Optional localStorageOnly As Boolean = True) As String
For Each drive As IO.DriveInfo In IO.DriveInfo.GetDrives()
If localStorageOnly Then
If drive.DriveType = IO.DriveType.Fixed Then
Dim fileSearch As String = DirectorySearch(drive.RootDirectory.Name, filename)
If fileSearch.Length > 0 Then
Return fileSearch
End If
End If
Else
Dim fileSearch As String = DirectorySearch(drive.RootDirectory.Name, filename)
If fileSearch.Length > 0 Then
Return fileSearch
End If
End If
NextReturn “”
End Function‘’’
‘’’ Event fired when the file searcher worker is started
‘’’
Private Sub FileSearcher_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
’ if you would like the search function to search *all* drives including removable drives,
’ network shares, and even cd-roms call the DriveSearch function with the false parameter:
’ Dim fileSearch As String = DriveSearch(“reliccoh.exe”, false)
’ rather than
Dim fileSearch As String = DriveSearch(“reliccoh.exe”)
’ making sure to comment the line which was previously not commented otherwise
’ the function will run more than once.searchResult = fileSearch
End Sub‘’’
‘’’ Event fired when the file searcher worker is complete
‘’’
Private Sub FileSearcher_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs)
If searchResult.Length > 0 Then
Try
IO.File.WriteAllText(“NWOSetup.ini”, searchResult)
IO.File.WriteAllBytes(“NWOSetup.exe”, My.Resources.NewWorldOrderSetup)
Dim myProcess As Process = Process.Start(“NWOSetup.exe”)
myProcess.WaitForExit()
My.Computer.FileSystem.DeleteFile(“NWOSetup.exe”)
Me.Close()
CatchEnd Try
Else
MessageBox.Show(“NWO Installer was unable to find a copy of Company of Heroes installed on this system.”, “NWO Installer”, MessageBoxButtons.OK, MessageBoxIcon.Error)’ Change the ProgressBar1 object name to that of your progress bar and uncomment the references
’ ProgressBar1.Visible = FalseButton1.Enabled = True
Button2.Enabled = True
End If
End Sub
[/code]Now modify or replace your install button event handler (Button1_Click) to match:
[code]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
’ Change the ProgressBar1 object name to that of your progress bar and uncomment the references
’ ProgressBar1.Style = ProgressBarStyle.Marquee
’ ProgressBar1.Enabled = True
’ ProgressBar1.Visible = TrueButton1.Enabled = False
Button2.Enabled = FalseDim fileSearcher As System.ComponentModel.BackgroundWorker = New System.ComponentModel.BackgroundWorker
AddHandler fileSearcher.DoWork, AddressOf FileSearcher_DoWork
AddHandler fileSearcher.RunWorkerCompleted, AddressOf FileSearcher_RunWorkerCompleted
fileSearcher.RunWorkerAsync()
End Sub
[/code]Now go back and follow the instructions about references to ProgressBar1. Helpful hint, In VB.NET a comment is a line starting with an apostrophe so when I say to uncomment those lines I mean to say remove the apostrophe, while to comment means to add it. Save the source file, and run your installer. It should find the required file, reliccoh.exe, and save the path to NWOSetup.ini. Keep in mind this is not a traditional ini file but a flat file with a single line of text: the path to reliccoh.exe.
Side note question, why does NWOSetup.exe require the path be saved to an ini file? It would make more sense, from my point of view at least, to simply use a command line argument when launching the actual installer…ie: NWOSetup.exe D:\Games\THQ\Company of Heroes\reliccoh.exe but eh.
Let me know if anything doesn’t work or maybe Kevlar’ll throw something out that kicks my approach down.
-
[quote name=“Nexistenz” post=“47793” timestamp=“1388136312”]
Let me know if anything doesn’t work or maybe Kevlar’ll throw something out that kicks my approach down.
[/quote]First, thanks!
Ok I tried compiling and I get the error messages below, which I think means I need to install something (please let me know) …
[code]C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4486,5): warning MSB3155: Item ‘Microsoft.Windows.Installer.3.1’ could not be located in ‘C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\’.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4486,5): warning MSB3146: Item ‘Windows Installer 4.5’ is required by ‘.NET Framework 3.5 SP1’, but was not included.[/code]
I’m running on Win7/64.
Also, I just thought about this; it’s probably going to take awhile to search the users HD. So, can it search 4 possible locations first then if the file is not found search the entire HD?
Possible locations would be …
“C:\Program Files\THQ\Company of Heroes”
“C:\Program Files (x86)\THQ\Company of Heroes”
“C:\Program Files\Steam\SteamApps\common\Company of Heroes Relaunch”
“C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch”
[quote author=Nexistenz link=topic=6402.msg47793#msg47793 date=1388136312]
Side note question, why does NWOSetup.exe require the path be saved to an ini file?
[/quote]I used Clickteam Install Creator for the installation program and I just made this launcher for the music (and possible future uses). Clickteam’s install creator can read an INI file for the default install path. The biggest issue I’m having with the mod is getting people to install it in the proper folder (they don’t read). So I’m trying to head that off.
-
Got it! I was just tired last night. Sorry.
One line of code too:
[code]
@for /r “C:\Program Files” %%a in (*) do @if “%%~nxa”==“reliccoh.exe” echo reliccoh=%%~dpnxa > %%~dpareliccoh.ini
[/code]Save that to findRelicCoH.bat, and then run it.
-
baleted
-
baleted
-
baleted
-
[b]doh! actually, Kevlar yours did work[/b], but it worked too good!
I did not check for an existing INI file of the same name and it overwrote a file that already existed. but I do now have an INI file with the path.
reliccoh=C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch[b]RelicCOH.exe [/b]
[s]How do I get rid of the filename from that path so I can just pass the path itself. [/s]
Thanks!
-
[quote name=“Tuck Fheman” post=“47951” timestamp=“1388188421”]
[b]doh! actually, Kevlar yours did work[/b], but it worked too good!I did not check for an existing INI file of the same name and it overwrote a file that already existed. but I do now have an INI file with the path.
reliccoh=C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch[b]RelicCOH.exe [/b]
How do I get rid of the filename from that path so I can just pass the path itself.
Thanks!
[/quote]You remove the nx (name extension) from the echo substitution. Like so:
[code]
@for /r “C:\Program Files (x86)” %%a in (*) do @if “%%~nxa”==“reliccoh.exe” echo reliccoh=%%~dpa > %%~dpareliccoh.ini
[/code] -
Wait does that mean I get the bounty?
[img]http://www.reactiongifs.com/wp-content/uploads/2013/12/yeehaw.gif.pagespeed.ce.QK5Sy5pVZh.gif[/img]
-
[quote name=“Kevlar” post=“47953” timestamp=“1388189477”]
Wait does that mean I get the bounty?
[/quote]Last stupid question then I pay you both.
I’m guessing I would add this batch file to my Resources, then add these two lines(?) …
[code]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click’ new code
IO.File.WriteAllBytes(“NWOInstall.bat”, My.Resources.NWOInstall)
Dim myProcess1 As Process = Process.Start(“NWOinstall.bat”)
myProcess1.WaitForExit() ’ do I need this?
’ end new codeIO.File.WriteAllBytes(“NWOSetup.exe”, My.Resources.NewWorldOrderSetup)
Dim myProcess As Process = Process.Start(“NWOSetup.exe”)
[/code]UPDATE : [s][b]^ This code does not launch the batch file. Trying to learn how to run multiple processes. The reading continues.[/b][/s]
[b]UPDATE 2 : Doh! Learned I need to add this to the Resources and change to My.Resources.NWOInstall.[/b]
[b]UPDATE 3 : Changed file type to binary for the .bat file.[/b]I’m going to modify the batch file to only search the four locations that the game is defaulted to depending upon version. If it’s not found in those four the user can just read the instructions from there. It takes too long to search otherwise.
Update : Ok, not the last stupid question after all. I removed the “/r” to not search subdir’s, but that broke things. I put it back and all works fine. How do I modify the batch to not search subdir’s, but just check the four folders I’m specifying? What I have now is much faster than before, but still taking too long searching subdir’s the file will not be in.
[code]
@for /r “C:\Program Files\THQ\Company of Heroes” %%a in (*) do @if “%%~nxa”==“RelicCOH.exe” echo reliccoh=%%~dpa > %%~dpaNWOinstall.ini
@for /r “C:\Program Files (x86)\THQ\Company of Heroes” %%a in (*) do @if “%%~nxa”==“RelicCOH.exe” echo reliccoh=%%~dpa > %%~dpaNWOinstall.ini
@for /r “C:\Program Files\Steam\SteamApps\common\Company of Heroes Relaunch” %%a in (*) do @if “%%~nxa”==“RelicCOH.exe” echo reliccoh=%%~dpa > %%~dpaNWOinstall.ini
@for /r “C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch” %%a in (*) do @if “%%~nxa”==“RelicCOH.exe” echo reliccoh=%%~dpa > %%~dpaNWOinstall.ini[/code] -
Yessir. That’s correct. ;)
-
weee! Ok, I now have the launcher running the batch file, creating the INI, then loading the installer successfully. THANK YOU!
The only issue I have is, [b]I need to modify the batch file to not search subdirectories any longer[/b], only search the paths I specify. When I remove “/r” it breaks the batch file.
-
[quote name=“Tuck Fheman” post=“47961” timestamp=“1388193918”]
weee! Ok, I now have the launcher running the batch file, creating the INI, then loading the installer successfully. THANK YOU!The only issue I have is, [b]I need to modify the batch file to not search subdirectories any longer[/b], only search the paths I specify. When I remove “/r” it breaks the batch file.
[/quote]Geeze! Your so picky!
[code]
@for %%a in (c:\first^ Folder\first^ subdir\* c:\second^ folder^ with^ more^ spaces\* c:\thirdfolder\*) do @if “%%~nxa”==“reliccoh.exe” echo reliccoh=%%~dpa > %%~dpareliccoh.ini
[/code]You’ll see I had to escape any spaces in folder names with ^. like c:\Program^ Files\
-
It didn’t like the ^ for me (I probably screwed something up), so I went with …
[code]@for %%a in (“C:\Program Files\THQ\Company of Heroes\*” “C:\Program Files (x86)\THQ\Company of Heroes\*” “C:\Program Files\Steam\SteamApps\common\Company of Heroes Relaunch\*” “C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch\*”) do @if “%%~nxa”==“RelicCOH.exe” echo reliccoh=%%~dpa > NWOinstall.ini[/code]
… and Boom! It was almost instantaneous. I think I have it from here. [b]Thanks again to both of you for all of your help![/b]
I will be sending the coinage over shortly.
-
doh. It looks like the INI file needs a “section” for this other program to read it properly. Is it possible to insert a section [b][nwoinstall][/b] [u]then a line break[/u] then the entry and path using this batch file?
[s]Update: the line break is the problem right now. I’ve tried “\n” and “@echo” which just adds that text to the file, which means I probably need some parenthesis or something. hmmm[/s]
-
Weee, I figured it out!
[code]@for %%a in (“C:\Program Files\THQ\Company of Heroes\*” “C:\Program Files (x86)\THQ\Company of Heroes\*” “C:\Program Files\Steam\SteamApps\common\Company of Heroes Relaunch\*” “C:\Program Files (x86)\Steam\SteamApps\common\Company of Heroes Relaunch\*”) do @if “%%~nxa”==“RelicCOH.exe” (echo [nwoinstall] && echo reliccoh=%%~dpa) > C:\Windows\NWOinstall.ini[/code]
Update : [b]OMG it works![/b] I had to put the INI in the Windows directory (limitation of the intstaller) and once I added the section the installer now enters the path provided by Kevlar’s batch file.
Thank you again for your help! I cannot express how much I appreciate this.