Set directory for xna StorageDevice on windows - xna

I am using easystorage framework to save my game data on Xbox360 and Windows. It works fine, but on Windows it seems to be hardcoded to save data in MyDocuments. After looking sourcecode of easystorage framework, i have found that the problem is undelaying Microsoft class StorageDevice.
Implementation on Windows
User storage is in the My Documents folder of the user who is
currently logged in, in the SavedGames folder. A subfolder is created
for each game according to the titleName passed to the
BeginOpenContainer method. When no PlayerIndex is specified, content
is saved in the AllPlayers folder. When a PlayerIndex is specified,
the content is saved in the Player1, Player2, Player3, or Player4
folder, depending on which PlayerIndex was passed to
BeginShowSelector.
http://msdn.microsoft.com/en-us/library/bb200105.aspx
So my question is: Can i somehow reconfigure StorageDevice or StorageContainer classes on Windows so, that my saved data will be saved for example in %appdata%?

Related

Check if JSON file exists in directory - Swift

I currently have a file in my project directory in Xcode. I am new to swift and all I would like to do is check if the file exists.
Picture of project directory
I created a resources directory and put it in the project. I added my file "GEOJson.json" and I just want to check for its existence and have a boolean value returned.
I am eventually going to need to read from the JSON file and import the contents into my project.
Extra:
Eventually this file is going to need to be pulled from a remote server as it will be constantly updating and inside it will be objects with GPS coordinates that need to be added to my map kit. The GEOJson file will be sitting on a mesh network that we set up and the app will need to pull the file off a directory on the network when connected to it and update the map. The end goal is that the file's existence is checked for on the server, if it exists it will be pulled periodically and the contents will update said map markers. If anybody has any idea how to do this the help would be much appreciated!
You can try this
if let file = Bundle.main.path(forResource: "GEOJson", ofType: "json", inDirectory: "Resources") {
print(file)
}
//
If you want to edit it then you have to copy / download - it out of main Bundle say in Documents , then process it there

Electron: How to set a custom directory for user data (--user-data-dir)

I want to set the --user-data-dir of my electron app to a custom directory, in my case, I would like it to default to a folder in the public directory so any users running the app will share the same asset directory.
It doesn't seem like Electron's appendSwitch() function supports this (and didn't work when I tried), so i'm kind of lost on how to implement this switch.
In an application built with Electron, you usually get the default user data directory dynamically by using app.getPath(name) from the main process:
const { app } = require ('electron');
const userDataPath = app.getPath ('userData');
It is also possible to set the path to a custom directory by using app.setPath(name, path):
app.setPath ('userData', "path/to/new/directory");
Overrides the path to a special directory or file associated with
name. If the path specifies a directory that does not exist, the
directory will be created by this method. On failure an Error is
thrown.
You can only override paths of a name defined in app.getPath.
By default, web pages' cookies and caches will be stored under the
userData directory. If you want to change this location, you have to
override the userData path before the ready event of the app module is
emitted.

Can't read saved file from documents directory

I'm trying to save a downloaded file so I can open it in another session. I'm saving the mp3 data to the documents directory, and I'm saving the url to the file in a local datastore. When I check using
if ([[NSFileManager defaultManager] fileExistsAtPath:musicObject[#"localFile"]]){
NSLog(#"applicationDocumentsDir exists");
}
else {
NSLog(#"File doesn't exist");
}
it returns "File doesn't exist", but I know it does because I've printed out the documents directory which gives me
"file:///private/var/mobile/Containers/Data/Application/94552DFC-022B-4962-9CB7-CCD87CB43E57/Documents/xDDsCbXAFhwEqGIzJfJRByEr1.mp3",
and I'm trying to access it with the same path but the first is private. How do I make the file not private (I have saved it earlier in the app)
file:///var/mobile/Containers/Data/Application/AE27BD8F-5EEB-48FC-A8D4-E228F99CECE3/Documents/xDDsCbXAFhwEqGIzJfJRByEr1.mp3
I suggest the following steps:
Take the last path component (that's just your mp3 filename)
Get the current Documents directory
Build a new path with the current Documents directory and the extracted mp3 filename
If I remember correctly, /var is a symlink to /private/var. So depending on how the path is built, one may end up with one or the other.
I inherited a project which was struck by the same problem, only with an extra randomly named directory in between. Eventually I removed the leading /private component, constructed an array of path components and checked, whether replacing non-existent elements with the current value leads to an existing file. You case should be easier to handle.
I don't remember when, but at some point the application directory (the hex numbers path component) began to change with almost each run in the simulator. Beginning with this behaviour such problems became much more visible. Although one should not save full paths, I suspect a lot of projects didn't care in the past. On one hand because things just worked, and on the other hand because a lot of people just don't know it.

Simple storage not persisting data between sessions

I'm trying to use the simplestorage from my extension, but I can't retrieve values between browser sessions. Here's the thing: From my main code, I created a value this way:
var ss = require("sdk/simple-storage");
ss.storage.foo = [{id:"bar1", properties:{a:"aaa", b:"bbb"}}]
console.log(ss.storage.foo);
This is ok, I coud see the object through the log. But then I closed the browser, commented the "foo definition" (line 2) and the console log was "undefined".
I know cfx run by default uses a fresh profile each time it runs, so simple storage won't persist from one run to the next. But I'm using
cfx -b firefox run --profiledir=$HOME/.mozilla/firefox/nightly.ext-dev
So I'm sure I'm using the same profile everytime.
What could be happening? What am I missing? Any idea is welcome! Thanks in advance!
Thanks to the answer of Notidart, I could discover that the problem was the file is saved when you close Firefox in the right way. When you just kill it through console, it's not persisting data.
This is how simple storage works. It creates a folder in your ProfD folder which is your profile directory: https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/simple-storage.js#L188
let storeFile = Cc["#mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("ProfD", Ci.nsIFile);
storeFile.append(JETPACK_DIR_BASENAME);
storeFile.append(jpSelf.id);
storeFile.append("simple-storage");
file.mkpath(storeFile.path);
storeFile.append("store.json");
return storeFile.path;
The exact location of the file made is in a your profile folder, in a folder named jetpack then your addon id, then a folder called simple-storage, then in a file in that folder called store.json. Example path:
ProfD/jetpack/addon-id/simple-storage/store.json
It then writes data to that file. Every time your profile folder is recreated (due to the nature of temp profile, due to jpm / cfx), your data is erased.
You should just use OS.File to create your own file to save data. OS.File is better way then nsIFile which is what simple-storage does. Save it outside that ProfD folder, so but make sure to remove it on uninstall of your addon otherwise you pollute your users computers
Just in case someone else finds this question while using jpm, note that --profiledir is removed from jpm, so to make jpm run using the same profile directory (and thereby the same simple-storage data), you have to run it with the --profile option pointing at the profile path - not the profile name.
jpm run --profile path/to/profile
For future readers, an alternative to #Noitidart's recommendation of using OS.File, is to use the Low-Level API io/file
You can create a file using fileIO.open(path). If the file doesn't exist, it will be created. You can read and write by including the second argument fileIO.open(path, mode).
The mode can be:
r - Read-only mode
w - Write-only Mode
b - Binary mode
It defaults to r. You can use this to read and write to a file (obviously the file cannot be in the ProfD folder or it will get removed each time jpm / cfx is run)

querying documents directory objects ios

I have images in uitableview, they each have a string for they're path in documents directory.
Now my trouble is if somebody adds the same image they will have the same path.
I was thinking of making an if-statement that will run on all of my fetchedResultsController objects or better yet my entire documents directory and append a number or something to the pathString.
lets say user adds title.jpg to doc directory, then he adds the same image then I want a check to see if it already exists, if it already exists in doc directory then append title(1).jpg so it can save properly and so on.
any efficient way of doing that ?
Depending on the OS you're targeting you can set the image name using NSUUID. If you're targeting < iOS 6 you'll have to use CFUUIDRef. This will always ensure you have a unique filename for an image.

Resources