Rename/backup file to a random name in Inno Setup - inno-setup

I know that I can rename any file with:
function RenameFile(const OldName, NewName: string): Boolean;
I already have this:
RenameFile(ExpandConstant('{app}\myfile.dll'), ExpandConstant('{app}\Myfile.dll.old'));
Which I can rename my file to any desired name, but in this case I need to rename it with a random generated name, I tried to use: ExpandConstant('{app}\Myfile.dll.{tmp}')); to get the random name generated by {tmp} but that did not work.
Is there any idea how to make it work?

You can use Random function:
ExpandConstant('{app}\Myfile.dll.' + IntToStr(Random(1000)))
Though, it does not prevent you from generating an already existing name. You should at least test, if the generate name exists. And if it does, then try a new random name. But then it makes no sense to use a random name. You can use incremental numbers instead, as those have better semantics.
See How to find an unique name to rename/archive old directories in Inno Setup.

Related

Using implicit path name argument in glob

I am using glob.glob() to read all the png files in a directory. This is what I am using now
for filename in glob.glob('D:\test_files\**\*.png',recursive=True):
...
Image files are kept in sub folders in test_files. The code will be used by someone else within another thousands of lines of codes. Hence, the directory should be defined somewhere else in the code as a string. Also I would like to change *.png by using another for loop. So, I need something like
for filename in glob.glob('imagepath'+'extension',recursive=True):
...
where imagepath is defined somewhere else in the code and extension is kept in a list. Can I use the glob.glob() method in this way?
The answer is here. I define the path like path = 'D:\test_files\**' and keep the extensions in a list like imgExtentions =['\*.jpg', '\*.png']. Then simply I use glob:
for extension in imgExtentions:
for filename in glob.glob(path+extension,recursive=True):

Inno Setup shorten file path string to fit FilenameLabel

On the WizardForm.InstallingPage, the WizardForm.FilenameLabel automatically truncates the string containing the file path, to include the drive letter at the beginning, followed by the maximum displayable path, truncating from the top level of the path, to fit the size of the label, so that the file name is always shown e.g. C:\...\LongFilePathNameWithMultipleSubDirectories\Filename.ext.
I have looked at the Length, Pos, Copy and ExtractFileDrive String Functions, but given that there are an almost infinite number path and file name possibilities, as the user can choose any installation path they wish, I am struggling to work out a way to show the maximum possible length of the path, without truncating the file name.
I think I need a function like Pos that returns the number of matches and the index for every \ it finds, which would mean I could use Length between each index to determine where to Copy from, but I haven't been able to find any way of doing this.
The MinimizePathName() function is available to scripting, it takes a string & a font and returns a reformatted string that will fit in a given number of pixels in the given font.
You can use MinimizePathName function.
Something like this:
YourLabelControl.Caption :=
MinimizePathName(
'C:\First Folder\Second Folder\Third Folder\Filename.ext',
YourLabelControl.Font, YourLabelControl.Width);
(untested)

In IDL, how can I access a variable given its name?

I would like to convert a string to a variablename, so it can be read as a already restored variable.
So, I look through a file, and look at all the files. I use RESTORE to use the file in IDL, restore names this object as something slightly different. It names it as an object which we'll call map_1 (in the code it's called filerestore_name). This is related to the file name and I can recreate this variable name - however, its saved as a string.
Now, I pass this onto the make_cool_video procedure. However, althoughthis string now is exactly the same as the varialbe name, its still a string!.
Thus, as its a string, the procedure can't work.
filenames=FILE_SEARCH('rxrt*')
filenames_withoutextension = STREGEX(filenames,'rxrt_[0-9]+[a-zA-Z_]+',/EXTRACT,/FOLD_CASE)
restore, '/home/tomi/Documents/actualwork/'+filenames_withoutextension(18)+'.idl_sav',
filerestore_name = STRJOIN(STRSPLIT(filenameswithout(18),'_[0-9]+',/EXTRACT,/REGEX),'')
PRINT, filerestorename
make_cool_video, EXECUTE(filerestore_name),filename=filerestorenames, outdir='/path/to.file/'
retall
What I tried: using the RESTORE function and the associated RESTORED_OBJECTS to store pointers in an array, and then referring to the array. But I couldn't get the restore function to form an array.
Using EXECUTE(filerestore_name) however, this doesn't convert it as I was expecting.
I would recommend using SCOPE_VARFETCH() instead (it isn't as limited as EXECUTE() and is probably more efficient). You can do something like:
make_cool_video, (SCOPE_VARFETCH(filerestore_name)), filename=filerestorenames, outdir='/path/to.file/'
I wrote this, then immediately thought of the answer.
So,
Convert everything to a string:
string1 = "makecooljes, "+ filerestore_name, outdir='file/to/path/'"
result= EXECUTE(string1)

IDA reset function name

I'd like to set the name of my renamed functions back to their actual ones. I've been able to generate the name sub_123456, but setting it with MakeName(addr, name) aswell as with MakeNameEx(addr, name, flags) always fail due to the reserved prefix.
Has somebody been able to achieve this already or do I have to use a custom prefix?
Thank you
If you pass an empty name, IDA will restore the automatically generated name. This usually works with functions and data.

How can I copy picture and text from one file into another file dynamically using node.js

Suppose i have two files a_b_c_d.txt and e_f_g_h.png S,At runtime i.e., by using command prompt i have to create b folder inside that c folder inside that d folder inside that a.txt and same also for another file f->g->h->e.png and i have some text in a and image in epng . .So,how can I get values from those existing file into created files. .
You can find all the file system operations inside the fs module. http://nodejs.org/api/fs.html
But like tapan says if you need to do complex synchronous execution that manipulates the file system something like Bash will be a lot better suited for that.
So if I'm understanding you correctly you want to take a file named "a_b_c_d.txt" in some folder, and move that into a nested folder as:
./a_b_c_d.txt -> ./b/c/d/a.txt
The general solution would be:
Grab the file name using process.argv if it varies.
For example, if you supply the file as an argument to node, e.g.
node move.js "a_b_c_d.txt", the argument, "a_b_c_d.txt", will be in the argv array.
Process the file name using a combination of string and array methods.
Nodes current directory is stored in the __dirname global variable
if you need it.
You can split the extension from the rest of the path
using string's split(...) method.
For the above argument, split('.') will result in the array ['a_b_c_d', 'txt']
You can then split 'a_b_c_d' using '_',
and use various array operations to pull the file name 'a'
out of the array, so that you're left with the path ['b', 'c', 'd']
and the file name and extension sitting in their own variables somewhere.
Use fs.mkdirSync(...) on the path array to make each nested folder,
starting with b (e.g. using array's forEach(...) method).
You could also use the async fs.mkdir(...) and supply callbacks,
but the sync version is easier in this case.
Finally use fs.renameSync(...) to move ./a_b_c_d.txt to ./b/c/d/a.txt.
As you can see, python or bash (as tapan suggested) would probably be simpler for this use case, but if for some reason you have to use node, the above advice will hopefully be enough to get you started.

Resources