Last active
May 3, 2017 23:42
-
-
Save capnmidnight/efae7f88bfcff584542e7ed1db1c353e to your computer and use it in GitHub Desktop.
Resolve missing directories and save a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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