/build/static/layout/Breadcrumb_cap_w.png

dynamic filename (yes im being lazy)

anyone tried to dynamically set a filename during installation.

i know i can do by editing the table prior to execution just wondering if there is an easier way im being lazy figured someone has probably done it already and can save me the test effort.

would be nice if the filename column was "formatted"

0 Comments   [ + ] Show comments

Answers (9)

Posted by: captain_planet 12 years ago
Black Belt
2
By the way, John, I know this doesn't fix your hardcoded iniFile entries, but I thought afterwards that my code would only update one IniFile entry so I updated it below and added some loops. Only trouble is, because of the limited SQL querying, you have to rename some files like this:

renameFilename "EXAMPL~1.TXT|exampleoldfile.txt","whatever.txt","INSTALLDIR"

Which can be easily fixed, but potentially overkill for what you want.

Also, it renames files/inifiles per directory too. So if John.txt existed in 2 directories, you can specify the correct directory.

Dim sInstaller, sDatabase, view, oldRecord, newRecord, filekey, dirRecord, dirview
Const msiViewDelete = 6
Const msiViewModifyInsertTemporary = 7

renameFilename "EXAMPL~1.TXT|exampleoldfile.txt","whatever.txt","INSTALLDIR"
renameIni "name1.ini","test.ini","INSTALLDIR"

'Both functions accept oldfilename, newfilename and file directory as arguments

Function renameFilename(oldFileName,newFileName,directory)

Set sInstaller = Session.Installer
Set sDatabase = Session.Database

Set dirview = sDatabase.OpenView("select `File`.`File` from `File`,`Component` where `File`.`Component_` = `Component`.`Component` AND `File`.`FileName` = '"& oldFileName & "' AND `Component`.`Directory_` = '" & directory & "'")
dirview.Execute

Set dirRecord = dirview.Fetch
While Not dirRecord Is Nothing
filekey = dirRecord.StringData(1)
Set dirRecord = dirview.Fetch
Wend
Set dirview = Nothing
Set dirRecord = Nothing

Set view = sDatabase.OpenView("select * from `File` where `File` = '"& filekey & "'")
view.Execute

Set oldRecord = view.Fetch
While Not oldRecord Is Nothing

view.Modify msiViewDelete, oldRecord

Set newRecord = sInstaller.CreateRecord(8)

newRecord.StringData(1) = oldRecord.StringData(1)
newRecord.StringData(2) = oldRecord.StringData(2)
newRecord.StringData(3) = newFileName
newRecord.IntegerData(4) = oldRecord.IntegerData(4)
newRecord.StringData(5) = oldRecord.StringData(5)
newRecord.StringData(6) = oldRecord.StringData(6)
newRecord.IntegerData(7) = oldRecord.IntegerData(7)
newRecord.IntegerData(8) = oldRecord.IntegerData(8)

view.Modify msiViewModifyInsertTemporary, newRecord

Set oldRecord = view.Fetch
Wend

Set view = Nothing

Set oldRecord = Nothing
Set newRecord = Nothing

Set sDatabase = Nothing
Set sInstaller = Nothing

End Function

Function renameIni(oldFileName,newFileName,directory)

Set sInstaller = Session.Installer
Set sDatabase = Session.Database

Set view = sDatabase.OpenView("select * from `IniFile` where `FileName` = '"& oldFileName & "' AND `DirProperty` = '" & directory & "'")
view.Execute

Set oldRecord = view.Fetch
While Not oldRecord Is Nothing

view.Modify msiViewDelete, oldRecord

Set newRecord = sInstaller.CreateRecord(8)

newRecord.StringData(1) = oldRecord.StringData(1)
newRecord.StringData(2) = newFileName
newRecord.StringData(3) = oldRecord.StringData(3)
newRecord.StringData(4) = oldRecord.StringData(4)
newRecord.StringData(5) = oldRecord.StringData(5)
newRecord.StringData(6) = oldRecord.StringData(6)
newRecord.IntegerData(7) = oldRecord.IntegerData(7)
newRecord.StringData(8) = oldRecord.StringData(8)

view.Modify msiViewModifyInsertTemporary, newRecord

Set oldRecord = view.Fetch
Wend

Set view = Nothing

Set oldRecord = Nothing
Set newRecord = Nothing

Set sDatabase = Nothing
Set sInstaller = Nothing

End Function
Posted by: captain_planet 12 years ago
Black Belt
0
John,

I thought since your blogs had helped me so much in the past that I'd try knocking something up. I originally thought about a CA which changes the filename during the current session using an UPDATE query. For some reason, the UPDATE query didn't work (MSI API errors if I recall). So staying down the same route, I deleted the row from the session, and reinsterted a temporary row containing the same values (apart from the filename!). It appears to work ok for me. Although handling the regression side of things may need additional logic, since the filename was only changed during the session.....I'll leave that one in your capable hands. [;)] Schedule it as Immediate, just before InstallInitialise (or even just before InstallFiles would work too).....

renameFilename "File1","whatever.txt"

'function accepts file primary key and new filename as arguments, although can obviously be adjusted to take oldfilename/newfilename etc
Function renameFilename(filePrimaryKey,newFileName)

Dim sInstaller, sDatabase, view, oldRecord, newRecord

Const msiViewDelete = 6
Const msiViewModifyInsertTemporary = 7

Set sInstaller = Session.Installer
Set sDatabase = Session.Database

Set view = sDatabase.OpenView("select * from `File` where `File` = '"& filePrimaryKey & "'")
view.Execute
Set oldRecord = view.Fetch
view.Modify msiViewDelete, oldRecord
view.Close

Set view = sDatabase.OpenView("select * from `File` where `File` = '" & filePrimaryKey & "'")
view.Execute
Set newRecord = sInstaller.CreateRecord(8)

newRecord.StringData(1) = oldRecord.StringData(1)
newRecord.StringData(2) = oldRecord.StringData(2)
newRecord.StringData(3) = newFileName
newRecord.IntegerData(4) = oldRecord.IntegerData(4)
newRecord.StringData(5) = oldRecord.StringData(5)
newRecord.StringData(6) = oldRecord.StringData(6)
newRecord.IntegerData(7) = oldRecord.IntegerData(7)
newRecord.IntegerData(8) = oldRecord.IntegerData(8)

view.Modify msiViewModifyInsertTemporary, newRecord
view.Close

Set view = Nothing

Set oldRecord = Nothing
Set newRecord = Nothing

Set sDatabase = Nothing
Set sInstaller = Nothing

End Function
Posted by: jmcfadyen 12 years ago
5th Degree Black Belt
0
love your work. I did pretty much the same and failed the first time around using the update statement too. I eventually got it to update and found even if I re-queried this logic it appeared to be a happy camper but when the file delivered it was still the original name. At that point I gave up as I needed this out yesterday some uber urgent thing they didn't want to wait on the real result.

I will use your code and whip up a custom table to handle the regression and conditional rename logic based on component state etc. I appreciate your time on this right now time is something I don't have much of. Doing this in wix takes a little patience :-) *smirk*

if you want a sample of the custom table code etc give me a shout. nothing fancy just usual CustomActionData / schedule / exec stuff.

who would have thought renaming a stupid file would be so much fun. probably doesn't help that all the parent directories were dynamic as well
Posted by: jmcfadyen 12 years ago
5th Degree Black Belt
0
one other point of contention was that the file I was renaming also happened to require text replacements as well so the scheduling was kind of important due to stuff moving and other tables accessing the moved files in moved directories. I can see why everyone else gave up lol.

i cheated for now but this is a good reason to write a table to handle this in the future I am sure someone else will want it one day.
Posted by: captain_planet 12 years ago
Black Belt
0
Thanks, John. Sounds like one hell of a package!

PS - I've just realised that there's no need to write additional logic to handle regression! Like a plonker, I only scheduled this CA to run on install! But if you condition it to run on install AND uninstall, it works like a charm!! Doh....[:)]
Posted by: jmcfadyen 12 years ago
5th Degree Black Belt
0
so as it turns out this is a real pain in the @$$.

so the stupid inifile table uses hardcoded filenames as opposed to fileKey references. As such the above rename of ini files causes the inifile replacements from the inifile table to fail due to incorrect filename formats.

this seems like a flaw in the table design. not sure if I am missing something but it would appear this is a design flaw to me. i never noticed before as I never tried to rename an inifile.

so now I have to rewrite the entire inifile table on the fly as well.
Posted by: pjgeutjens 12 years ago
Red Belt
0
Well if you're on that path anyway, might as well add 2 extra tables like FileRename and IniRename, containing something like

_FileKey Not Null
NewName Formatted

and similar for an IniRename table.. or even just the one FileRename table with a CA that checks the ini file table in one go.

Then I guess Captain's scripts could be used as CA to run through these. Or have I gone completely off the deep end? [:D]

PJ
Posted by: captain_planet 12 years ago
Black Belt
0
Hmmm....lost me there a little bit John. Not sure why the IniFile table would need to reference the file table? And File.FileName and IniFile.FileName are the same data type? (FileName) I quickly adapted the script for the iniFile table, and it worked fine for me on installation and regression.....Scheduled just before InstallInitialise, Immediate, No condition set.....

renameFilename "centrica.txt","whatever.txt"
renameIni "ini1","test.ini"

'function accepts file primary key and new filename as arguments, although can obviously be adjusted to take oldfilename/newfilename etc
Function renameFilename(filePrimaryKey,newFileName)

Dim sInstaller, sDatabase, view, oldRecord, newRecord

Const msiViewDelete = 6
Const msiViewModifyInsertTemporary = 7

Set sInstaller = Session.Installer
Set sDatabase = Session.Database

Set view = sDatabase.OpenView("select * from `File` where `File` = '"& filePrimaryKey & "'")
view.Execute
Set oldRecord = view.Fetch
view.Modify msiViewDelete, oldRecord
view.Close

Set view = sDatabase.OpenView("select * from `File` where `File` = '" & filePrimaryKey & "'")
view.Execute
Set newRecord = sInstaller.CreateRecord(8)

newRecord.StringData(1) = oldRecord.StringData(1)
newRecord.StringData(2) = oldRecord.StringData(2)
newRecord.StringData(3) = newFileName
newRecord.IntegerData(4) = oldRecord.IntegerData(4)
newRecord.StringData(5) = oldRecord.StringData(5)
newRecord.StringData(6) = oldRecord.StringData(6)
newRecord.IntegerData(7) = oldRecord.IntegerData(7)
newRecord.IntegerData(8) = oldRecord.IntegerData(8)

view.Modify msiViewModifyInsertTemporary, newRecord
view.Close

Set view = Nothing

Set oldRecord = Nothing
Set newRecord = Nothing

Set sDatabase = Nothing
Set sInstaller = Nothing

End Function

Function renameIni(filePrimaryKey,newFileName)

Dim sInstaller, sDatabase, view, oldRecord, newRecord

Const msiViewDelete = 6
Const msiViewModifyInsertTemporary = 7

Set sInstaller = Session.Installer
Set sDatabase = Session.Database

Set view = sDatabase.OpenView("select * from `IniFile` where `IniFile` = '"& filePrimaryKey & "'")
view.Execute
Set oldRecord = view.Fetch
view.Modify msiViewDelete, oldRecord
view.Close

Set view = sDatabase.OpenView("select * from `IniFile` where `IniFile` = '" & filePrimaryKey & "'")
view.Execute
Set newRecord = sInstaller.CreateRecord(8)

newRecord.StringData(1) = oldRecord.StringData(1)
newRecord.StringData(2) = newFileName
newRecord.StringData(3) = oldRecord.StringData(3)
newRecord.StringData(4) = oldRecord.StringData(4)
newRecord.StringData(5) = oldRecord.StringData(5)
newRecord.StringData(6) = oldRecord.StringData(6)
newRecord.IntegerData(7) = oldRecord.IntegerData(7)
newRecord.StringData(8) = oldRecord.StringData(8)

view.Modify msiViewModifyInsertTemporary, newRecord
view.Close

Set view = Nothing

Set oldRecord = Nothing
Set newRecord = Nothing

Set sDatabase = Nothing
Set sInstaller = Nothing

End Function
Posted by: jmcfadyen 12 years ago
5th Degree Black Belt
0
i just sat down to do this and you beat us to it.

as for the reference to the inifile table its because the file I am renaming is an ini file which requires replacements.

but due to the fact the inifile table has a hard coded reference to the file table after the rename of the file the inifile replacements don't hit the correct file location so i need to update the entire inifile table as a result of the file rename action.

pjgeutjens

one step ahead of you there I am writing those tables as I can see this happening again in the future. Once this place settles down in demand I will publish it all back for future reference. but it looks like captain planet may have beaten me to it. I will test now.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ