Using backslash (\) to indicate subfolder in ios - ios

Please bear with me while I try to explain my problem
Suppose the folder structure of my download container's Document folder is represented /A/B/C/, which I have obtained through the proper API's in ViewController.m. I am porting a PC C++ project to ios, where, at one point the program decodes it's input to get the name and full path of a file, for example, as images\background.png. Since my program automatically locates the Document folder through API's, it is supposed to create the folder structure /A/B/C/images\background.png. The program I am porting to ios also contains a directory creator function, which detects the locations of / in the pathname string, checks whether a directory by that name is already present or not (for example, it would detect /A as being present, but /A/B/C/images would be detected as absent, as images has not been created yet). The function creates all the subfolders in this tree if they do not exist already. After the directory structure has been created (/A/B/C/images), the program does something like this to create the file (background.png in this example):
.
.
.
Create directory structure
fid = fopen(`/A/B/C/images\background.png`, "wb"); // note that full path `/A/B/C/images\background.png` is automatically determined by the program by the time it reaches this point
.
.
file writing code
fclose(fid)
.
.
My problem is that after creating the folder images, it creates the png file as images\background.png, instead of creating a background.png inside the images folder. I have already ported this program to android NDK and it creates the png file inside the images folder as expected, so I can only assume that android considers \ to indicate a subfolder while ios doesn't.
What can be done in order to get background.png created inside the images subfolder? Any idea will be appreciated.

Related

How to loading outside .love save file? (love2d+ LUA)

I write editor and game and it requires a save game option.
I Just want use a Save folder in game folder. not inside.love
How to get a bug.
Start game
Enter menu by Escape key
Press save game - this create savegame
Press Load game - you get an error "File not exist" but you write this file seconds ago.
I successful save a game in savesm2k folder but it folder outside .love file and i don't know how correct load saved game.
Used engine: Love2d 0.10.2
OS: Linux Mint 18.1 x64bit
I read many manuals and I'm stuck.
For loading save game i use this commands
lsg=love.filesystem.getSaveDirectory().."/M2k-Saves/m2ksave"
lsg=love.filesystem.getSourceBaseDirectory().."/M2k-Saves/m2ksave";
data, size = love.filesystem.read (lsg);
leveldatacopy=freadbin (data);
Why does the program not try read existing file? and report no exist? I try using another command but using GetSaveDirectory broke function WriteMAP (requires for binary map and data writing) etc. but it write files which cannot be loaded in load section.
Maybe I should use LUA for reading files direct from folder but I don't know how to correct DO it.
example with bug.
https://github.com/dj--alex/m2ktest
file m2ktest-load-savegame-test.love
At this moment on every saving i manually replace saved game inside love archive (!) . This is not normal.
Anybody can tell me how i get and correct open saved file? Not from inside .love file . from outside of course. If levels and configs can be readed from love file inside save files must be outside. I can only can create files outside love file . i know love file is a zip archive.
If required i can post a .love file but is game completely done and have 150kb of clean code.
You should not prefix paths with love.filesystem.getSaveDirectory() or love.filesystem.getSourceBaseDirectory(). This is done automatically, internally to the love.filesystem functions. Saying
lsg = "/M2k-Saves/m2ksave"
data, size = love.filesystem.read (lsg)
leveldatacopy = freadbin (data)
should work, and will place the file in the save directory / outside of the .love file or game directory. (Love forbids writing anywhere except in the save directory.)
Love's filesystem model is like a "stack" of filesystems. For file reading, it first looks in love.filesystem.getSaveDirectory() with whatever path you pass in. If it finds a file, it uses that; otherwise it looks inside the love.filesystem.getSourceBaseDirectory() (or – if packed – inside the .zip / .love file). Writing files always goes to love.filesystem.getSaveDirectory(), you cannot write to love.filesystem.getSourceBaseDirectory() (because it may not be an actual directory but a zip file).

Show Content of app file after unzipping the iPA, and opening exec shows my local path

I've developed an application and I need to remove my computer local path from the generated iPA file.
I did the following:
unzipping iPA file.
click on show package content.
open exec(appname.exec) file with text editor.
Now I can see some binary stuff, and strings with my computer local path (with my mac name).
I have to remove these paths from the exec file, due to security issues. How can I do so?
As Accessing Files and Directories says:
Although you can open any file and read its contents as a stream of bytes, doing so is not always the right choice. OS X and iOS provide built-in support that makes opening many types of standard file formats (such as text files, images, sounds, and property lists) much easier. For these standard file formats, you should use the higher-level options for reading and writing the file contents. Table 2-1 lists the common file types supported by the system along with information about how you access them.
You have many ways to save your data:
Specifying the Path to a File or Directory
Locating Items in Your App Bundle
Locating Items in the Standard Directories
Locating Files Using Bookmarks
You have chosen to Specifying the Path to a File or Directory,as #Droppy says
Firstly it will break the code signature and secondly it's time consuming and error prone.
You'd better choose to Locating Items in the Standard Directories
Here is why you should choose the way:
Locating Items in the Standard Directories
When you need to locate a file in one of the standard directories, use the system frameworks to locate the directory first and then use the resulting URL to build a path to the file. The Foundation framework includes several options for locating the standard system directories. By using these methods, the paths will be correct whether your app is sandboxed or not:
The URLsForDirectory:inDomains: method of the NSFileManager class returns a directory’s location packaged in an NSURL object. The directory to search for is an NSSearchPathDirectory constant. These constants provide URLs for the user’s home directory, as well as most of the standard directories.
The NSSearchPathForDirectoriesInDomains function behaves like the URLsForDirectory:inDomains: method but returns the directory’s location as a string-based path. You should use the URLsForDirectory:inDomains: method instead.
The NSHomeDirectory function returns the path to either the user’s or app’s home directory. (Which home directory is returned depends on the platform and whether the app is in a sandbox.) When an app is sandboxed the home directory points to the app’s sandbox, otherwise it points to the User’s home directory on the file system. If constructing a file to a subdirectory of a user’s home directory, you should instead consider using the URLsForDirectory:inDomains: method instead.
You can use the URL or path-based string you receive from the preceding routines to build new objects with the locations of the files you want. Both the NSURL and NSString classes provide path-related methods for adding and removing path components and making changes to the path in general. Listing 2-1 shows an example that searches for the standard Application Support directory and creates a new URL for a directory containing the app’s data files.
You cannot do it this way. Firstly it will break the code signature and secondly it's time consuming and error prone.
The correct approach is to not use the complete path in your code and instead use methods like NSSearchPathForDirectoriesInDomains to get the Documents folder, or whatever directory you want to use.

NULL when using fopen with xcode

I am trying to initialize a multidimensional array from a file using C for a iPhone 4inch app but I can't open up the file using fopen.
Whenever I try this I get a NULL:
FILE *f;
f=fopen("/level1.rez", "r");
if (f == NULL)
{
printf("Error Reading File\n");
//exit (0);
}
I am not sure how to open files using C.
I tried this already:
I printed out the current working directory using getcwd but all I got was "/" and when I attached that to the file name I still got NULL.
I read that if you go to product > scheme > edit scheme then options you can change the current working directory but I don't see that option.
Also I read that you can use absolute paths like: /users/name/desktop/program
but I am new to iOS development so I don't know if that is a good idea.
So how do I get fopen to work?
You CAN specify absolute paths in iOS, but the path in your example is probably used in Mac OS, which is laid out a little differently. You can specify paths to fopen() as you say, but there is more work to finding out what the first part of that path really is.
The iOS puts all AppStore apps into folders with randomly generated sandbox directory names. It is basically the the hexadecimal string of a GUID. So you need to use methods from iOS frameworks to get the first part of the path (or URL) to your file.
If the file is part of the app bundle so it can ship with the app, then you will need to use NSBundle methods to find the path to the file.
If the file is generated or downloaded after the app starts up on the device, then you need to use NSFileManager methods to determine the path to the directory of the file. (Typically the Documents directory. You can build a directory structure of your choice within the sandbox.)

Changing output directory in MVC Application

I am having a problem with my MVC application after I set a different output folder instead of the default Bin folder . I also deleted the bin folder .
This resulted in Global.asax file exception "Cannot load the type Global.Mvc application" during application runtime.
I am trying to get rid of all the bin folders to have just one output folder for my application . I would like to know if it is possible at all to get rid of the bin folder completely . Am I missing some setting here or is it a must to have bin folder ?
I find a way to change bin folder.
Just like you say, When we change the default output folder:"bin\", then it will display some exception, Maybe that's a bug from visual studio.
Actually a lot people want to change the default bin folder to some RAM disk position, then it will save HDD life(don't let the HDD always write again and again), also very fast for read and write.
We can't change the default address, but we can change it use this way(delete bin folder before):
Open CMD.exe(administrator mode), put this code and execute:
mklink /d "Your project folder\bin" "new address(like RAM disk address)\bin"
mlink can redirect the original folder position to new position. Then, all fine such like you need.

Delphi - How to get Directory with OpenDialog using iPhone as a picture source

I have a Delphi app (D2010) which lets the user select a JPG file via an OpenDialog. When I select the file from a normal Windows directory, my TOpenDialog.Filename contains the FULL PATH to the file, and my code works. The issue I am running into is that the user will often be copying the file phone a cell phone. When the user plugs in the phone, runs my code, the TOpenDialog Shows the files on the cell phone, the user picks the proper jpg file, but the TOenDialog.Filename does NOT contain the path to the file (only the name of the file), so my program cannot find the file.
For both CAMERAS and CELL PHONES, the picture directory is the DCIM directory. For whatever reason, Windows 7 and probably all others, does NOT provide a drive letter to this directory. As such TOpenDialog only returns the file name, not the full path name. This means I cannot copy the file since I don't have a full path name.
So in short, my question is: How do I use TOpenDialog to get the full path name, when the path is a storage area on a cell phone (in my case, iPhone 5). XE5 has a routine called GetCameraPath, but D2010 does not.

Resources