Skip to content

Instantly share code, notes, and snippets.

@capnmidnight
Last active May 3, 2017 23:42
Show Gist options
  • Save capnmidnight/efae7f88bfcff584542e7ed1db1c353e to your computer and use it in GitHub Desktop.
Save capnmidnight/efae7f88bfcff584542e7ed1db1c353e to your computer and use it in GitHub Desktop.
Resolve missing directories and save a file.
class ScoreTable {
// blah blah blah
}
static string ScoreFilePath = PathX.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AndTheory", "Dodgewall", "scores.js");
void Save(ScoreTable scoreObject)
{
var parts = ScoreFilePath.Split(Path.DirectorySeparatorChar);
var rebuild = parts[0];
for(int i = 1; i < parts.Length - 1; ++i)
{
rebuild = PathX.Combine(rebuild, parts[i]);
if(!Directory.Exists(rebuild))
{
Directory.CreateDirectory(rebuild);
}
}
File.WriteAllText(ScoreFilePath, JsonUtility.ToJson(scoreObject));
}
ScoreTable Load()
{
if(File.Exists(ScoreFilePath))
{
return JsonUtility.FromJson<ScoreTable>(ScoreFilePath);
}
else
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment