\[CLOSED\] 1000 DogeCoin + 10 FTC for Assistance w/VS Express 12 (n00b aLeRt)
-
[glow=red,2,300]UPDATE 12-27-2013 : This issue has been resolved and the bounty has been won.[/glow]
[b]NOTE :[/b] [glow=red,2,300]I have zero skillz [/glow](I have no idea what I’m doing). What I have so far was accomplished by watching intelligent people in youtube videos and reading forums then copying what they’ve done into my hack.
[b]MY PROJECT : [/b][u]I have an installer for a game mod[/u], which is far more complicated than it needs to be (see the NOTE above) but I don’t care.
[b]What I need to figure out[/b] [sub](and have tried on my own for two weeks to no avail)[/sub] [b]is how to[/b] …
- Locate a specific EXE file anywhere on the users computer.
- Get it’s full path.
- Create an INI file, insert the path in #2, save the INI file in the same folder as #1 file (so it can be read by another program which loads next).
- Figure out where I put this code in my project (see NOTE above).
I’ve found a few snippets of code that say they accomplish what I’m trying to do, but when I put it (haphazardly) into my code it’s causing errors. I’m sure I’m not “defining” something properly or I’m adding this stuff in the wrong place, which brings me to the point of this thread.
[b]I need help and I’m willing to tip a little DogeCoin (1,000 to be exact) and 10 Feathercoin to the person that can solve this problem for me.[/b] I can provide my current [s]code[/s] hack for reference or if you could just guide me where to insert the code I can do the rest. Once I can get it to compile and confirm it’s working I will send over the DOGE+FTC and possibly a bonus for help that exceeds my expectations. ;)
Here’s an image of the (alpha) installer …
[img]http://i1061.photobucket.com/albums/t467/TuckFheman/nwoart_zpsdccb5a58.jpg[/img]
;)
-
You mean you want to do a filesystem search?
-
[quote name=“zerodrama” post=“47757” timestamp=“1388109055”]
You mean you want to do a filesystem search?
[/quote]Yep. I want to locate a file called reliccoh.exe and get it’s full path, then write that path into an INI file in the same folder where reliccoh.exe resides.
-
Let’s start with the basics.
I’m going to assume you want to do this on a windows box, and without installing any dependencies. So that limits us to exe files, and batch scripts.
The second sounds appealing. Let’s see if we can do that.
First, let’s find the file.
Windows batch scripts have for loops, so all we need to do is generate a list of all possible files from all possible directories, and if we have the right file, do step 2.
[code]
for /r “C:\Program Files(x86)” %%a in (*) do if “%%~nxa”==“reliccoh.exe” set p=%%~dpnxa
if defined p (
echo %p%
) else (
echo File not found
)
[/code]Copy that to findRelicCoH.bat, then type ‘findRelicCoH’.
[code]
C:\Users\TSavo>findRelicCoHC:\Users\TSavo>for /R C:\progra~1 %a in (*) do @if “%~nxa” == “reliccoh.exe” set
p=%~dpnxaC:\Users\TSavo>if defined p (echo ) else (echo File not found )
File not foundC:\Users\TSavo>touch c:\progra~1\Java\reliccoh.exeexe
C:\Users\TSavo>findRelicCoH
C:\Users\TSavo>for /R C:\progra~1 %a in (*) do @if “%~nxa” == “reliccoh.exe” set
p=%~dpnxaC:\Users\TSavo>if defined p (echo C:\PROGRA~1\Java\reliccoh.exe ) else (echo Fi
le not found )
C:\PROGRA~1\Java\reliccoh.exe
[/code]And we’re in business.
Now, the next part is we need to get that into a ini file?
…
An hour and a half later and I still can’t get it.
Stupid batch files.
[code]
@for /r C:\progra~1 %%a in (*) do @if “%%~nxa”==“reliccoh.exe” set I=%%~dpnxa
for /f %o in (%~fI) do echo %o%\reliccoh.ini
[/code]If anyone can figure out why that doesn’t give me the right path, please take the bounty. You’ve earned it.
Otherwise I’ll write you a very small exe in C# tomorrow. It’s bed time tonight.
-
What I have is in VB and is zipped up below. I’m not sure if I’ve included everything needed, so let me know if I’ve missed a folder or files that are required. I grabbed what looked like the bare necessities.
[url=https://www.dropbox.com/s/k4zu9bsvn9kx5ji/NWOcode.zip]https://www.dropbox.com/s/k4zu9bsvn9kx5ji/NWOcode.zip[/url]
This file is basically a launcher for the actual installer and I need for this program to pass the path of RelicCOH.exe to the installer via an INI file by locating the file on the HD, then creating an INI file with RelicCOH.exe’s full path.
Thanks!
-
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]