Can I attach files directly to the executable in Rust? [duplicate] - rust

This question already has answers here:
How to embed resources in Rust executable?
(2 answers)
Closed 7 months ago.
I have a DLL file that I want to copy to several locations on the computer.
I don't want this file sitting around in my folder like a potato, so I want the file placed directly into the executable and copy it from there instead.

Short answer: You can but depending on use case it might not always be best way to get thing done.
Use include_bytes! or include_str!
If it is something like README file, Lisence, json config or something use include_str! macro
If it is some binary file like DLL you just mentioned use include_bytes
Keep in mind that:
If you are trying to enclose raw file which is large in size or you are including multiple files, it will brings all the drawbacks of having huge binary file.
Instead you can include the code to download that file if it can be hosted.
Even better, if you are distributing your package as application, you can back everything in AppImage or deb file. I believe windows and mac have something similar.

Related

How to reference or link files and folders inside a git repository to match these criteria?

I've encountered a problem long time ago which I couldn't solve, but I'm curious whether it's possible to fulfill ALL of the below listed criteria at once or not.
The solution what I was looking for can:
somehow refer to an existing file or folder from another folder of the same git repo
basically reach the content of the file or folder from another subfolder, see the content(s) as if they were on the another path as well
e.g.: if ./path/to/folder is referred from ./another_path/different_folder, then every file in ./path/to/folder/* is visible on path ./another_path/different_folder/*
e.g.: if ./path/to/file is referred by ./another_path/different_file, then by reading/writing content of the different_file, the original file is read/modified
store the referred file only once in git repo
don't want to make a copy of the file to another path and maintain changes in both files simultaneously
be able to use multiple references for a single file
be able to use relative paths
make it work on both Windows and Linux
As if I can remember, some of the problems were while experimenting with this:
the paths were broken after the repository was pulled to a different path (I assume they were not relative, but absolute)
the Windows style links are special files, were not working on Linux
the symlinks can't handle relative paths correctly on the Windows system
the hardlinks resulted duplicating files in Windows
(I can't remember exactly which if these might be incorrect, but I'll experiment with the problem again and try to update this question.)
Is there any workaround for this problem?
Thank you for any help!
Please note (in case you would like to mark this question as a duplicate), that there are other similar questions here, but none of those questions define this set of the criteria, therefore it can't be a duplicate.

How do I tell my program to search for a file that may have a slightly varied filepath?

So I have a program right now that reads text files from a folder. They are in a separate folder than the one my program is in, and both of them are in a dropbox folder together. Right now if I want to read one of these .txt files I'll do
file='/Users/JohnDoe/application/folder/file.txt'
text=open(file,'r').read()
print(text)
and it works just fine on my pc. The problem is that if I open my dropbox on another computer and run this program, it won't work because the filepath will probably be slightly different. Is there a way to work around this? Maybe a module that searches for files using something other than filepath, or something like that.
I'm brand new to python and to programming in general so any suggestions are appreciated. Thanks.
If you know the specific name of the file, but you're unsure where it might be located on another machine, you can use os.walk like this previous answer suggests. Or you can read up on using regex (regular expressions) in Python like this previous answer suggests.

When using cx_freeze, what files have to be updated to update the application?

I want to implement an autoupdater in my Python application. This is no problem with the source version; Python doesn't care at all that the script it's running is trying to overwrite itself.
Windows, however, does care if an EXE tries to overwrite itself. My question is, does my EXE even have to overwrite itself? Or is the EXE just an interpreter, and I only have to overwrite library.zip?
If it does, is there any alternative to starting an updater application and shutting down the main EXE?
The cx_Freeze exe is compiled along with cx_Freeze, so in most cases you can safely leave it alone and just update library.zip. However, you should make sure that you prepare your updates using the same version of cx_Freeze that you froze the application with originally, in case it expects specific things about the files around it.
Also, the exe gets stamped with a version number relating to your application (you can see it in the file properties). If you don't replace it, that version number won't change.
If you do need to replace the exe, I believe the trick is to copy it to a temporary folder and re-run from there, so that it can replace the original. You can also look into update frameworks like Esky, which aim to handle these kinds of details for you. I haven't used that, so I don't know how well it works.

AutoIt unzipping files

I've been searching all day for a solution to unzip a file with AutoIt Script. I would like to unzip a file called full.zip to a folder.
This is my last place to turn since I can't find a solution of my own. I have found many solutions made by others; AutoIt3 files containing functions, but the code has issues of which I do not understand, and I'm unable to them copy here because I'm using a screen reader and it doesn't seem to format properly. This is why I can not copy code here.
Does anyone know of a method, tutorial or resource that I can use to unzip a file with AutoIt?
Thanks for any help,
josh.
There are a lot of solutions people have coded. A few examples are the 7zip UDF, Zip.au3, zipfldr UDF. If those are not working for you it is most likely because of small changes to AutoIt, which is usually just #incudes being restructured.
I usually just keep 7za.exe (7-zip's standalone executable, 7-zip can be downloaded from here, and then after installing you can copy the 7za.exe from its program directory).
Then it becomes as simple as a call to RunWait to create the archive:
RunWait("7za.exe a MyNewArchive.zip file1.ext file2.ext ...")
And then to unzip:
RunWait('7za.exe x MyArchive.zip -o"Path\To\MyOutputFolder"')
The 7-zip FAQ also mentions that you can use this exe in your own applications (including commercial ones) provided you mention it in the documentation and provide a link. That means you are ok to use FileInstall(...) to include 7za.exe in the compiled .exe.

Can a Self Extracting Zip File read a registry entry?

I'm trying to get my website to talk to a friend's program. Think ITunes - one main program with hundreds of thousands of little things installed into it. We don't want to have to create an InstallShield install program for each of those hundreds of thousands of little things.
We have the files grouped into the folder sub-structure.
We have a .REG file for what registry entry needs to be added to see the new folder group.
But is there a way to do a self extracting zip file that reads a registry entry so we know where they installed the original program to be able to dump the new files there as well? I want them to double-click the EXE and click Finish and for everything to work.
(I've been looking into INF and CAB files through IExpress.exe, but haven't found the answer. I remember Package for the Web didn't have an option to read a registry entry, but did let you modify the suggested install path.)
Thanks so much.
Best wishes,
Andrea
But is there a way to do a self extracting zip file that reads a registry entry so we know where they installed the original program to be able to dump the new files there as well? I want them to double-click the EXE and click Finish and for everything to work
Well, yes and no. There are self-extractors that can run a program after extracting all files. DotNetZip, for example, can produce an SFX which can do this.
Just an aside: a normal SFX is just a zip file, with a "stub" executable merged with it. The stub exe can do anything it wants to do, but the most basic thing it does is extract the files in the zip. When you use DotNetZip to produce an SFX, it embeds its particular stub into the zip. That stub knows how to extract files, and also knows how to invoke a program after extracting. You can also produce your own stub that can do other more exotic things.
So you could use an SFX for your purpose. When run, it would extract, then invoke it's extra program. The program could look in the registry, then move or relocate the extracted files to the appropriate place. Then terminate.
For a different twist, the SFX might have just two files: the program-to-run (the one that reads the registry, and another embedded zip. Then when the SFX runs it generates 2 files. Then it invokes the program-to-run, which reads the registry, then unpacks the contained zip and puts the files into the desired place.
Ok, so you could do it.
Should you?
mmm, maybe. This really is an installer, so, you should decide whether you want to use a zip as an installer. Don't forget, if you use an SFX as an installer, there's no good way to uninstall.
Have you tried Inno Setup toolchain? It's a bit better than a bare Self-Extracting ZIP file, it's a setup creation utility. I'm convinced it has got something to put some entry in the Registry, look also at the plugins.
Basically, a self-extracting executable that alters the registry, it's a setup program. So why don't you go for a proper one?
Website: http://www.jrsoftware.org/isinfo.php

Resources