Old 20th November 2015, 20:51   #1
Bungkai
Junior Member
 
Join Date: Nov 2015
Posts: 23
Regular expressions for path?

Been looking through google to try to find something similar. Shows me the NSISpcre plugin. Not particularly against it or anything, but I'm new to NSIS already and if I don't need it I'd prefer not to use it.

I'm basically looking to build an installer for a plugin that would install files into a particular location. The path however, from different versions would vary from computer to computer.
ex. C:\Program Files\[A random program]\[Program Name 2012]\
C:\Program Files\[A random program]\[Program Name 2015]\

How would I go about expressing different version numbers? Same goes for Program Files as there is 32bit version of windows and 64 bit version of windows.

Any help would be greatly appreciated.
Bungkai is offline   Reply With Quote
Old 21st November 2015, 00:16   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Assuming that the application is installed under a certain fixed path is a bad idea! You could try to search for the application (recursively), using the FindFirst and FindNext functions, but that's still slow and error prone. Instead, most applications will write their location to the registry - under a well-known registry key/value. So, in order to "detect" the install location, you just read the appropriate registry value.

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 23rd November 2015, 21:40   #3
Bungkai
Junior Member
 
Join Date: Nov 2015
Posts: 23
Okay so I've done what you've said with success. I'm able to find the path based off of the registry. My problem now is that a certain file is also year dependent. as in [ApplicationName][year].[fileextension].

I was able to use IfFileExists to find out if say [ApplicationName]20*.lsp (it's an lsp file I'm looking for) to find if a certain path contains that file in the year 2000 to 2099. It's able to do that. My question is now, how do I put this into a variable to use? Putting the asterisk in a strcpy statement, detailprint or a fileopen puts the literal character in there. I need to be able to open any year version basically whether it be a file in the year 2000 or the year 2099
Bungkai is offline   Reply With Quote
Old 23rd November 2015, 22:46   #4
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
If possible somehow, try to detect the exact file name from the registry. Or based on some other available info.

If it's really not possible and you have to search for the file at runtime, use something like:
PHP Code:
FindFirst $$"$INSTDIR\*.foo"
loop:
  
StrCmp $"" done
  DetailPrint 
"Found: $1"
  
FindNext $$1
  
Goto loop
done
:
FindClose $

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 24th November 2015, 17:30   #5
Bungkai
Junior Member
 
Join Date: Nov 2015
Posts: 23
Quote:
Originally Posted by LoRd_MuldeR View Post
If possible somehow, try to detect the exact file name from the registry. Or based on some other available info.

If it's really not possible and you have to search for the file at runtime, use something like:
PHP Code:
FindFirst $$"$INSTDIR\*.foo"
loop:
  
StrCmp $"" done
  DetailPrint 
"Found: $1"
  
FindNext $$1
  
Goto loop
done
:
FindClose $

It's possible but I'm unsure if the registry would be the same across all versions of the program.

So I'm trying to open it as soon as I find the file. I know how to read/write with NSIS, but the above code you posted I don't 100% understand. Is this piece of code solely to detect whether or not the file exists in the directory?

I want to be able to find the file, hold it in a variable (I've done up to this part), and then check the variable to see if it fits the regex pattern I stated in the thread and then open if it does match.

I just tried

PHP Code:
Strcmp $"(program)20*.lsp" found notFound 
where $0 holds the correct file name. I think the 2nd part where it compares $0 to a string is where it falls, it most likely takes the * literally instead of what I want it to do.
Bungkai is offline   Reply With Quote
Old 24th November 2015, 18:26   #6
Bungkai
Junior Member
 
Join Date: Nov 2015
Posts: 23
Never mind, I didn't need to do what I just posted. I'm just running loops in my head. Thanks a lot for your help.
Bungkai is offline   Reply With Quote
Old 24th November 2015, 18:37   #7
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
The code above iterates over all files that match the specified template. In the example I used "$INSTDIR\*.foo", so it would iterate over all .foo files in the install directory. But you can use whatever template you deem suitable for your needs...

For details see the NSIS manual:
http://nsis.sourceforge.net/Docs/Cha...html#FindFirst

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump