Can I save into a specific folder? - file-io

While learning how to create Lua file output code with the support of LÖVE, I've always hated that LÖVE filesystem handler always saved the specific file somewhere in C:/Documents and Settings/...
How can I create a code that saves a file into a specific folder that I'd like to define (and maybe to change while running the application)?

The love.filesystem library doesn't let you do anything outside the sandbox. However, LÖVE doesn't disable Lua's built in io library, so you can use io.open to open files outside the sandbox and read/write them as normal, as well as other Lua functions like require and loadfile.
It also doesn't restrict loading of external modules, so you can (for example) require "lfs" to load LuaFileSystem and use that, if it is installed.

Related

NSSavePanel for Mac Catalyst?

Objective: a sandboxed application for Mac Catalyst. I need to create a file for writing data on external drive.
As far as I understand, there should be some kind of dialog which grants permission to write data to a specific location outside of the app sandbox.
What kind of dialog should I use?
Usually I followed this procedure: create a file in the app documents directory and then use [UIDocumentPickerViewController alloc] initForExportingURLs to move this file outside of the sandbox.
But now I need to create a file for writing on external drive instead (file cannot be created in documents directory because it will exceed internal storage capacity, but external drive is big enough). What "save file dialog" should be used for that?
Ok, I found the solution.
Add a plugin to the Mac Catalyst project which allows usage of AppKit functions (NSSavePanel is declared in <AppKit/NSSavePanel.h>). Detailed explanation how to add such plugin is here: https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit
Create a function in that plugin which uses NSSavePanel.
Call this plugin function from main Mac Catalyst app.
Using this approach makes NSSavePanel to be displayed, and the chosen file has all necessary permissions for writing.

Where to write files on disk from my Sandbox app without User interaction?

I have designed an app for MacOSX. Its function is to manipulate PDf files.
First the user would import files "in" the app.
After manipulating the files, the files are saved and kept in the library.
Actually, it is exactly the concept of Library of iTunes. You have files inside and you don't bother where they are located. It is better if the user do not have to select any folder in the system.
My question is : Where do I write my files on the disk?
I know I have to write it in a specific place but I can't figure out where. I tried in the App Bundle but I read somewhere we can not with sandboxing and indeed it didn't work.
I know I can write my preferences in my NSUserDefaults. Can I write any files there?
You can store the files in the application support directory. Use NSFileManager to locate it as described here: URLsForDirectory
And read the sandbox documentation for further details.

How to automatically upload compiled coffeescript files in Intellij IDEA?

I use automatic deploy through FTP. Everything worked well until I started to use coffeescript and its filewatcher feature which recompiles my .coffee file into .js file on every change.
Problem is that IDEA don't want to upload these compiled files like others. So I have manually press hotkey to upload compiled file after every change, which I want to see on the server.
How can I do it more convenient to use?
There is an option to upload external changes automatically.
Right now IDEA will not perform synchronization after file watcher is invoked, so you will need to do File | Synchronize, IDE will detect the changes and upload them.
Next update will have an option for the file watcher to perform synchronization after execution as the result of addressing this feature request.
this feature request concerns to a possibility to synchronize all files in output directory on every change (required by some transpilers). But, AFAIK, this is not the case for CoffeeScript compiler - synchronization should work there. Do the generated js files appear in the Project View as soon as the compilation completes, or do you have to synchronize the view manually to see changes? In the latter case something must be wrong with file watcher configuration (output path set incorrectly, for example). If files are synchronized correctly, setting 'upload external changes' option should do the thing

Extra files in Windows Store app package

just wondering if it's possible to include some files (one txt file in this case) in the app package that I need in the application folder. The thing is that I might use a piece of code that requires the license to be included in the app as a text file, and I think this would be one way to do it.
Thanks in advance.
Absolutely, it's really no different than including images for instance. And if you need to process the file within your app you can access it via its local path or explicitly use the ms-appx:/// protocol.
See How to reference content and How to load file resources for more details.
Just include the file in your project with Build Action set to Content. You can put it in any folder you like.
The file can then be accessed from the app either using the ms-appx: protocol or using the StorageFolder API:
var license = await Package.Current.InstalledLocation.GetFileAsync("license.txt");

jars, external properties, and external file io

I checked quite a few similar questions, but so far I am unsatisfied with the solutions.
Ever use the Minecraft Server? At initial launch, it creates all the files and folders it needs, and allows you to make changes to files like Server.properties and ops.txt by making them external of the executable jar file.
I'm working on a similar project, and I want to duplicate that behavior. Everything works great when I run it in eclipse. When I export to a jar file though, things get funky. The external files and folders are created without a hitch, but afterword, it would appear as though they cannot be read from or written to. Any ideas how Notch made his server?
--edit--
Scratch that, it doesn't even appear to reliably create the files and folders. Maybe it only creates them the very first run after creation?
--edit again--
It creates them in the root directory. When I tested it in eclipse, the root directory was limited to the folder containing the project, and therefore looked fine. The solution was to make the class aware of it's location, and include it in all file operations.
Have the main class in your executable jar file look up where it is, then have it store that information in a global String or something. Prefix your filenames with that string in your file operations, and voila! It's writing to the correct directory.