Smooth Operator: Rename a file while writing to it - file

In Linux (probably also in Windows/OSX) if we open a file to write and while writing to it we rename it, the raku process goes smooth and keeps writing to the file as it should.
But how can we find the new name (path) of the file while the renaming happens?
IO::Notification is NOT the way to go because it gives no other information but only the general description:
FileRenamed or FileChanged
Is there a way to do it?

Short answer: No, not as far as I know.
Some technical background here: Rakudo on MoarVM (which is the only backend that supports IO::Notification afaik) depends on libuv for this functionality. If libuv doesn't support it, there only a very small chance that Rakudo will.
I have no idea if libuv supports that functionality. If it does, I suggest you make an issue in MoarVM to draw attention to this. Or even better, write a Pull Request to implement that functionality.

Related

What do you even call the ability of code to auto update and how do you do it?

I'm having a hard time understanding how to even search online for this behavior. I've seen it several times before and know it's something that can be done but don't know if this is a language level feature or what. What do you call the ability for code that you edited to automatically be applied to an executed instance of said code being run.
To use a common version of this that I see: you'll have a game that you're developing open and you'll be running that game in your engine and then edit a value (let's say one representing walking speed) and then simply save that file (maybe compile it? maybe just that line? I don't know how it's done) and then, suddenly, that behavior is updated in the live instance of the program just like that.
It seems so much better then having to recompile a file, or a whole project, and then run it to be able to test it. How do I do this kind of rapid iteration and what is it called? NOTE: the first time I saw this was with Clojure in emacs. Does that have something to do with it?
You may want to read about the Clojure REPL and also here.
"Hot Reloading" is related and is commonly used in UI development in the browser with ClojureScript:
Shadow CLJS
Figwheel Main

Proper GTK+ widget for selecting file save location?

I'm trying to make a GTK+ interface in glade that has you select where to save a file. I tried using the GtkFileChooserButton widget, but when I run it, I get the warning
Gtk-WARNING **: gtk_file_chooser_button_set_property: Choosers of type `GtkFileChooserButton' do not support `GTK_FILE_CHOOSER_ACTION_SAVE'.
and the dialog wants me to pick a file to open, not save.
After some google searching, it sounds like it has been depreciated to use a GtkFileChooserButton to select where to save a file. From the mailing list post I found, it sounds like this was depreciated because it promotes bad interface design.
Right now, I can't seem to find the right way to do it though.
So, what is the right way have a user pick where to save a file? What about when they need to be able to pick more than one file?
Sorry if I have no idea what I'm talking about, this is my first time actually trying to do something useful with GTK+ and C.
/* Since You did not provide a version, assuming GTK+3 stable */
Afer a quick look at the GTK+ reference manual, quickly found that the manual says GtkFileChooserButton can only be used for selecting a file or a folder for opening. For saving it suggests using either GtkFileChooserDialog, or GtkFileChooserWidget. Which one fits Your particular situation better, is up to You to decide. Consult with the manual for more info. Also, the whole GTK+ API documentation is here
Actually, it's best to look at the manual first, and only then, if no relevant information is found, try to google it.

How to create an undeletable file in Delphi

[the following is a rephrase of my previous question, which was deemed ambiguous].
I'm digging into creating a basic licensing mechanism for a demo application. What I have in mind goes like that: the application creates an empty "license file" called, say "0b1xa487x.ini" upon the first run, then expires 30 days after it has been first executed and can't be run anymore as long as that specific file is present on the system.
What I'm looking for is a method to protect that specific file in a way to deter deletion. Since it will be a blank file, devoid of any content, I wouldn't mind it to be corrupt, have corrupt headers, invalid date, whatever it takes to stay undeletable.
I've seen a similar approach somewhere based on file attributes (the file had the HX attributes set in place); however, the attribute approach lead me nowhere, as I can't find any documented feature on the existence of a file attribute X.
I also know that there are other approaches including rootkit drivers and system services launched as system user, but this particular one seems to fit best in this scenario. Again, I outline that the file's contents may as well be inaccessible, I'm not planning to use the approach in running any kind of malware from the file, as I've been accused below :)
Corrupt suggests not conforming to some standard. There are no standards for blank files.
Thanks everybody for your suggestions. I found a way to render my file inaccessible, namely by using fortunate combination of file permissions. The downside is that these things don't work on non-NTFS partitions. The good thing is that I can always clean up after my application by simply removing these permissions programatically and deleting everything afterwards.
Regarding your last answer to Henk, I believe it is more easier to create a service, start it automatically with the OS, and open the file in the fmShareExclusive by using a TFileStream.
But, you can not force the kernel of the OS, or an antivirus to make your file 'undeletable'.
Best regards,
Radu

Display processes that access a folder

I am trying to write a simple program, preferably in C, that will watch a given directory. Whenever a process accesses that directory, I just want to print out the name of that process. It seems simple, but I am coming up short for solutions on MSDN. Does anyone know which library calls I will need for this, or any helpful advice? I have considered repeatedly querying for what processes have handles on the given directory and just watching for additions to that list.This approach just seems very intensive and I am hoping there is an easier way. Thanks.
I'm not sure if there's an easier way, but one way is to use a file system filter driver. Or easier a file system minifilter driver.
You can filter, log, track, control, ... all IO.
There is no supported way to do this from user mode. You can use the FindFirstChangeNotification API to tell when a file or directory has changed, but that doesn't tell you who did it. You might be able to hook some things to obtain this information... but that is of course not supported.
If you can use a driver, you can use Event Tracing for Windows for this information. This is what Sysinternals ProcMon uses. But installation of a driver is a very invasive process, bugs in your driver cause BSODs, and installation of a driver requires administrative rights. Something to keep in mind.

Tricking programs in C

Say I launch a program from the program I make. Is it possible to trick the launched program into thinking the windows directory is in a different place?
If it uses the %windir% or %systemroot% environment variables to determine the Windows directory, it would certainly be easy to change these. But if it uses an API call, you'll have to hook that call, as ChrisW suggests. You might take a look at Detours.
Faking the location of the windows directory is generally not something that is done. My own reaction is similar to those above, that its a recipe for disaster if it were even possible.
If you could explain your situation in more detail (possibly in a new question), there might be better suggestions to solve your actual underlying problem.
It would be difficult. There are several system APIs which the program might be using to determine the path of the windows directory. To trick it you would need to intercept the program's calls to whichever API it is, and return a different result.
There are many articles about intercepting APIs on Windows: here's the first one I found using Google: API hooking revealed.
The location of Windows directory is in the Registry. Vista may let you change it per user, but as far as I know it's impossible to do per-process.

Resources