can I save a file to the current directory in air? - file

I have inherited an air app, and I don't know a lot of the capabilities and limitations of air. Can I open a local from the current directory for read and write?
Using FileReference, I have been able to save a file to my /Documents directory. But is there way to have it just save in the current directory? Or have the prompt that currently comes up default to the current directory instead of my /Documents dir?
I've read http://livedocs.adobe.com/flex/3/html/help.html?content=Filesystem_08.html, and can't figure it out.
Thanks

If current directory happens to be application directory, then no. AIR has concept of various directories:
File.applicationDirectory - where app itself is installed, read-only.
File.applicationStorageDirectory - buried somewhere deep (on Windows, it is C:\Documents and Settings[User name]\Application Data[Application name]\Local Store) - you can use it to store files.
File.documentsDirectory - shortcut to current user's documents directory. Do not throw garbage there.
File.desktopDirectory - shortcut to user's desktop, should be treated even more carefully.

Related

Directory path which does not physically exist on my device

I am learning Python programming language. Currently
I am experimenting i-o files. I imported sys module and
in sys.path list I saw two kinds of paths:
/data/data/org.qpython.qpy3....
/storage/sdcard0/qpthon...
The former path does not exist physically on my device
(Tablet), although I can create/read files using this
path through python.
I want to know about these paths.
What are they called?
What are they for? etc.
The first path, /data/data/org.qpython.qpy3, this is where the actual QPython app is stored on your device. I don't believe you can access this path without having root access.
The second path, /storage/sdcard0/qpthon, this is where QPython saves files by default. It uses this location because it can be easily accessed with normal user privileges.

saving file in "Program Files/myApplication" folder with fopen_s

My application saves its settings under its executable folder, which happens to be where it is installed under Windows(C:\ProgramFiles). The problem I'm having is that I use fopen_s and open the file as binary but when my application saves the settings Windows doesn't allow it. I'm thinking it has to do something with permissions but I'm not sure where to look. Maybe I should change the directory to where it saves the settings to something like users/Documents.
Any thoughts on this, and why it isn't working? Why is fopen_s not allowed to save a file where my application is installed?
Applications running under normal user privileges have read-only access to the %ProgramFiles% directory. This is by design. If it was possible to save files to this directory, then multiple users sharing the same PC (with different accounts) would overwrite each other's settings file.
Adjust your code to save it's settings to the %LOCALAPPDATA% directory. Use SHGetKnownFolderPath API to get this directory path.

Fopen returns null unless explored there?

This is a very odd error.
I am using Visual Studio 2012, and in a C++ project (as a container for a C project), I am loading a file in this way:
const char* fname = "SomeFile.csv";
if(!(fp = fopen(fname, "r")))
{
printf("Error! Could not open %s!\n",fname);
return;
}
The CSV is in the same folder as the .EXE, and that is the intention for this program.
1. When I run it in debug, it fails to read the CSV.
2. When I put in the full pathname to the file, it works correctly and loads the CSV.
3. When I go to the output folder in Windows Explorer, and run the .exe, it correctly loads the CSV.
4. Now here is the weird part. When I go to another folder (anywhere else), and I then paste in the full path including the .exe into Windows Explorer, it starts up the program, as it should, but it fails to read the CSV.
As a caveat, if I have the folder loaded in explorer, but run it in the VS2012 debugger, it also fails to load the CSV.
What is going on here? Why would it only find it if I am running it while the window is open in explorer?
fopen, open, etc. will, given a bare filename with no path components, attempt to open the named file in the "current directory". Given a filename without a filesystem root it will attempt to open the file in a directory relative to the current directory. Only when given an absolute (full) path will it look exactly where you've told it.
In a command-line based system, the current directory is pretty obvious - it's the directory you are in when you issue the command.
In a Graphical User Interface the notion of a current directory is a bit more mushy:
Navigate in Windows explorer to the program (let's say WORD.EXE) and double click it - the current directory is likely to be the directory where the program is - the place to which you navigated (but there's no standard that says this has to be the case)
Navigate to your documents for your project and double click a Word document, which launches WORD.EXE automatically - what is the current directory? It's likely to be where the document is.
Launch WORD.EXE from the Start menu - what the heck is the current directory now?
Launch your program from the debugger - now what is the current directory?
This last point is why you have to tell the IDE / debugger what to use as the current directory when it launches your program.
The fileOpenDialog doesn't exactly "default" to the current directory - it open to where you last opened it, without changing the current directory for the program - when you pick a file it then passes the full path of that file to the program.

Use Chrome portable to open a index.html file on the same USB stick for a homepage

IS it at all possible to set the Google homepage to a file located on my USB pen drive?
I can link it though the file path, problem being the drive letter would change depending on the system it is plugged into so a hard coded homepage link wont work.
Im unsure of the syntax to use to make it upen the file -
%USBDRIVE%/Webfiles/index.html
The page is used to help new users navigate the USB pen and get the info/files they require as its aimed as users with next to no IT skills or disabilities
Thanks Guys
You've probably found a solution already, but just come across your question and I recently had the same scenario. I'm assuming you mean on PC.
I solved it as follows:
In the PortableGoogleChrome folder (after portable chrome is setup on the usb drive), there is a default file called parameter.txt. I added the following in order to set the homepage to my local file. It is in a sub folder called 'resources' located on the usb drive root:
--homepage="\resources\index.html"
That's all for the parameter.txt file. That takes care of the homepage setting.
Now to launch portable chrome, I created a windows batch file called launcher.bat also at the root of the usb drive (call it whatever you like obviously!). I added the following code:
#echo off
cd PortableGoogleChrome
"ChromeLoader.exe"
The launcher file changes the directory to PortableGoogleChrome and then loads Chrome via ChromeLoader.exe which takes in your homepage or other parameters in Parameters.txt.
FINALLY, in order to create an application to replace the Launcher.bat file (as I figured a windows application with icon would be more intuitive to run than the batch file), I found a windows utility called bat_to_exe_converter which enabled me to convert the bat to an exe and supply an icon also (having tried to do so in C++, C# but errors because of needing supporting DLL's, this was much more straightforward).
Hope that's of use!

Icons from remote files

I have started coding an FTP client application (for fun). I’m trying to represent remotely hosted files with icons. For example, let’s say I’m browsing the root folder of an FTP server (/) and want to display the Backup.zip file with the icon association from that client operating system. On some systems, this may be the windows compression icon and other operating systems this may be WinZip or WinRAR icons.
I have the client browsing local files with the SHGetFileInfo() function. This works great with files that are local, however, this function requires the physical file in order to retrieve the associated icon. So, this will not work with remotely hosted files. I have found some samples of loading icons given a file extension, and this is really where the question comes in... What would be the best strategy to get icons associated to remote files?
Go to the registry every time and look up extension to icon associations
Create 1 byte files with each extension and use the SHGetFileInfo() function for remote files (using local 1 byte files as association for remote files)
Other strategies???
What would a professional software company creating an FTP client do?
Thank you for your time.
-Jessy Houle
I suggest that you don't go to the registry every time: go if you need to, but if you've already been for a given filetype then remember/cache that result (within your program) and reuse it.
Use the procedure here from a previous Stack Overflow question on the same idea and uses the registry instead of an actual file.
How can I get the filetype icon that Windows Explorer shows?

Resources