Creating an imageSheet using an absolute path in desktop

Question:  “When it is time to build these projects, how do you guys plan to get the content in the right place(s)?”  

I am quite sure that Corona won’t be able to build a project that has …/ paths in it.  I’ve done the same experiments you guys are doing and none of them panned out for long-term durability or clarity of organization.  

(I also experimented with various git structures/relationships and they turned out to be painful and unreliable too.)

I agree with Rob that your best choice here is a symbolic link (OS X) or Junction (Windows) to a folder(s).

I forgot to mention (and it seems this may be relevant), if you’re developing tools to access arbitrary folders and drives on OS X and Windows, I have a module for this coming soon in SSK 2.

Till new version of SSK is released, you can get your hands on the old version of that module here:

(Has dependencies on SSK so you may need to do a little work to extract it as a standalone module).

https://github.com/roaminggamer/SSKLegacy/tree/master/ssk/RGFiles

-- -- Module Legend -- ssk.RGFiles.\* documents.getRoot() documents.getPath( path ) resource.getRoot() resource.getPath( path ) temporary.getRoot() temporary.getPath( path ) desktop.getDesktopRoot() desktop.getDesktopPath( path ) desktop.getMyDocumentsRoot() desktop.getMyDocumentsPath( path ) desktop.getDrivePath( path ) by current OS. desktop.explore( path ) util.exists( path ) util.dumpAttributes() util.isFile( path ) util.readFile( path ) util.readFileToTable( path ) util.writeFile( data, path ) util.appendFile( data, path ) util.rmFile( path ) util.mvFile( src, dst ) util.cpFile( src, dst ) util.isFolder( path ) util.repairPath( path, forceForward ) util.rmFolder( path ) util.mkFolder( path ) util.mvFolder( src, dst ) util.cpFolder( src, dst ) util.saveTable( tbl, path, secure ) util.loadTable( path, secure ) Misc - Utilities ---------------- util.getFilesInFolder() util.keepFileTypes() util.getLuaFiles() util.getResourceFiles() util.flattenNames() util.findAllFiles()

-Ed

Well, I’d say the best choice would be to provide desktop specific endpoints like system.UserFolder, system.Desktop, system.ApplicationData and system.GlobalTemp, everything else is a hack to workaround limitations. From my perspective junctions and symlinks are asking/using too much power to solve a problem that does not require it. Junctions are a pretty low level operation that could definitely be a permission issue with non-admin users or in machines under corporate IT. Also if you create a symlink outside of the sandbox without declaring the entitlement, it could be seen as a problem in the Mac Appstore review (if caught). 

PS. Nice to meet SSK :slight_smile:

I have created a feature request to add these constants to Corona desktop. It can be found here. Vote it up if you would find it useful.

system.DocumentsDirectory, system.TemporaryDirectory and system.CachesDirectory should be in user specific locations for desktop builds.

For instance on Windows:

%HOMEPATH%\AppData\Roaming\<CompanyName>\<AppName>\Documents

%HOMEPATH%\AppData\Local\<CompanyName>\<AppName>\CachedFiles

%HOMEPATH%\AppData\Local\<CompanyName>\<AppName>\TemporaryFiles

On macOS it seems to be:

~/Library/Application Support/AppName/Documents

~/Library/Application Support/AppName/tmp                 – could be for both TemporaryDirectory and CachesDirectory

Of course on Unix based systems ~ is the user’s home directory. On macOS that’s /Users/username/ using me as an example /Users/rmiracle

This seems to be a different question than how I can you reference files relative to your app bundle which for mac OS is /Applications/ but isn’t guaranteed to be. 

I should have also added, Windows has a bunch of environment variables to help you find places to store files of certain types. This page gives you a good rundown of these variables:

http://www.rapidee.com/en/environment-variables

matias.kiviniemi

I think you misread me.

I am not suggesting sharing data between live apps with symlinks and junctions. 

Nor am I suggesting that app data live anywhere but in:

  • Resource

  • Documents

-Temporary

I am also NOT saying you can use RGFiles to magically display images from locations not listed above.  (RGFiles is for manipulating files not displaying images).

I am saying

  1. During development if you want to maintain a common library of functions/modules where all projects link to the same single location, then use symlinks and junctions.

  2. Same statement for common repositories of images and assets.

  3. If you are making private tools for yourself or distrbuted outside official channels, there are ways to access files from other locations to copy them into your own or otherwise manipulate them.  (Again, not to display them unless you first copy them into system.DocumentsDirectory.)

  4. If you use symlinks and junctions Corona will treat those links as if the folders are part of the actual structure and copy those resources into the build/binary.

If I read it right, the original purpose of this post was to find a way to keep a common set of content, where the instances live in one place, but are accessible in multiple projects.

I assumed the purpose of this was to simplify development and to ensure changes made to a common file would be seen immediately by all projects.

I also assumed that once you went to build, you would want those files copied into the target binary/bundle.

If I have mis-read the original intent of this post then let me know.

PS - You mentioned adding new paths similar to system.DocumentsDirectory, system.ResourceDirectory, et al. except pointing to the desktop.  While you can submit a official feature request for this (http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback), I don’t think it will get done any time soon as it competing against other higher priority items and opens a can of worms on permissions issues.

Can you provide a better description of what you’re trying to accomplish? What file paths you need access to? This thread is really hard to follow and figure out what the actual use case/end goal is.

Thanks

Rob

I’m sure we have different purposes but mine was to create an imageSheet from a PNG in system temp written by a Photoshop plugin. So I have two apps running in same computer but different environments that need to agree on an accessible folder with some consistent method that works on both Mac&Win. Previously it was just reading the TMP env variable which you have on both Win & Mac. Now I’ll likely be using system.TemporaryDirectory, change the plugin write there and handle the platform differences.

That said, I think there is a need for more general purpose roots as above. I.e. the core problem is that graphics.newImageSheet() takes a root and relative path. So it does not help parse user directory from env variables because you can’t pass that graphics.newImageSheet except with the “…/”-hack

Yes, we do have different purposes, but the solution is the same. Sorry to have hijacked this thread, but i think our problems have enough in common to not need another thread.

What i essentially need is to be able to load an image, anywhere on the disk. My app is a desktop (macOS and win) level editor. Imagine Gimp or Photoshop opening a png file. My app will come with bundled textures, but i want the user to be able to select their own textures from their own folder, so that their maps/levels can have their own personal look.

I can open json files with no problem since io.open can open absolute paths, and i can even execute os commands to get image files to my apps documents directory. I would just like to do it directly, by directly loading the image the user specified from the absolute path. that’s all. No extra files, no cleaning temporary directories, no extra junk.

I already have my own tools to do filesystem stuff, and already have enough experience with environment variables, i do not need any of those. (But it is cool you shared the info for others)

Since the thread title is “creating an imageSheet using absolute path in desktop”, i thought our problems were close enough. We both need a way to load images/sheets with an absolute path. So i already created the feature request and had already shared it, here is the link again.

As a recap:

  • The app is a desktop app, no iOS, no Android, no WP

  • I don’t need a folder to access a common set of content

  • I do need to load images from any place to show them to the user.

I think i could list at least a thousand desktop apps that can read any file on any disk, including Corona SDK, it can load my projects’ main.lua using relative paths.

It sounds like what you really need is a file picker.

I already have one (FIle picker). The path returned from it is an absolute path, which cannot be loaded by Corona directly: display.newImage(absolutePath)

Have you tried copying the file to system.TemporaryDirectory and opening it from there?