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).
Related
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.
I have a data file that I need to include with my app when I distribute it. When loading any files in the app, I prefix the file name with:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
This works great for anything I create within the app (and for reading back), like files I download in response to a user action. But I can't for the life of me figure out how to place files there when I build my app in Visual Studio.
I've tried making a "Documents" subdirectory in the special "Resources" folder, but that didn't work (I tried setting the "Build Action" to both BundleResource and Content). When I look at the folder for my app (from using the simulator) I can see that in the "Documents" folder there's all the files I downloaded, but I can't find my data file that I'm trying to bundle ahead of time. I even searched my entire hard drive on the Mac and still couldn't find said data file.
The data file isn't an image, if it matters. Just raw binary data. How do I set it up so that this file goes into the proper documents directory at compile time, so that I can read it using the SpecialFolder.MyDocuments prefix? Thanks.
You can't. You can include files in your app bundle, and then at startup copy them from the bundle into a user folder. But this won't happen automatically.
I'm only just getting started with Yeoman, trying to create a Generator that downloads WordPress, unzips it, and then proceeds to download my own WordPress starter theme.
The problem I'm having is that when I extract the latest.zip from wordpress.org (using this.extract()) it contains a wordpress/ directory resulting in my directory structure being my-project/wordpress/ rather than my-project/.
I've tried moving, copying and deleting the wordpress/ directory with various degrees of success; using this.fs.copy() I actually managed to get the files in the correct folder, but when trying to delete the original wordpress/ directory the user has to confirm deletion of every single file (not ideal). When I tried this.fs.move() I had to confirm each and every move instead.
I've found similar gulp/node.js questions on here, but I would prefer to use Yeoman's built in this.fs API.
Please note that I am aware of YEOPress but this is mostly for learnig purposes.
I ended up using the Node Package fs-extra instead as it deletes or moves without confirmation.
Recently I've ran into a big problem with pugiXml (used within cocos2d-x engine).
Shortly, I've made a quiz game (in mentioned Cocos2d-x). I keep my questions (and some other data) in an Xml file. On new game they get parsed and inserted into dictionaries. If a question is answered, a short string indicating the answer (whether it was good or not - Y/N) is inserted into that Xml file (below that particular question). Later, I use this data to show statistics (I count the percentage of questions with good answers - which is counting the amount of Y's divided by the amount of questions, multiplied by 100).
I use:
CCFileUtils::sharedFileUtils()->fullPathForFilename(o_QA);
to get the file and later
pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rb", &bufferSize);
to put file into buffer and
pugi::xml_parse_result result = doc.load_buffer(pBuffer,bufferSize);
to parse data and start working on it.
Finally, I save the file with:
doc.save_file(fullPath.c_str());
Android:
It's working very well, although I had to copy the file with questions to /data/data/app/Files/ . Still, It's keeping the changes on many devices.
iOS:
Unfortunately, on iOS it's not working. Data get loaded and parsed (which means, that I can actually play the game), but they are not saved. I've tried moving the files to other folders (started from Resources/Documents, then main Resources folder, Resources/Library/Application Support). It's still not saving the data and I don't know what to do. The result is my statistics not being counted well (it doesn't matter how you answer the questions - all of them are false, because the Xml file is not being updated).
Did anyone run into similar problem?
Can you, please, help me?
I am doing something similar in my own app, using both pugixml and cocos2d-x. So I can confirm this combination works well.
Rather, because on iOS you cannot both read and write the data from and to the app bundle (which is read only), you will need to implement a simple check in the writable document directory - If you a saved file there, load it, if not, load from the app bundle.
So in essence for loading, if your saved filename is "my_save.xml", here is an example flow:
1) Construct a path for your save file in the writable folder by concatenating the writable folder path + your filename. CCFileUtils should have something like getWritablePath() for that.
2) if the file exists in the folder, load it. Otherwise, go to 3).
3) Construct a path to your original data file from the app bundle, using CCFileUtils::sharedFileUtils()->fullPathForFilename(). Load the file from there.
For saving, simply do step 1 and save the file there.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I use Delphi to test if a Directory is writeable?
My program will download an update for the user if they request it. The user has to specify the location to save the installer. They might pick a directory which they don't have access to save something to. In this case the download starts (downloading to a temporary directory I assume) and we only know that it failed when it ends and tries to move the file into the folder.
Is there a simple way to check if we have write permissions on a folder in Delhi?
There is AccessCheck function or tricks, but this information is not reliable in generic case.
So, usually you just need to create file to check, if you have access for that.
For your specific case, you have the following choices:
After save dialog closing: try to
create a file in target folder with
the name of downloading file. Delete
it after check. Not pretty, since
you rarely may have access to create
files, but not to delete them.
After save dialog closing: try to create a
file in target folder with the name
of downloading file. Keep that
handle open and move file content to
it after download is complete. Not
pretty, since you can't move file,
you need to copy it.
(the right one?) Just bring save dialog again
on any access denied issues.