Skip to content

Commit

Permalink
Refactor file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
niezbop committed Dec 18, 2018
1 parent 055a6e8 commit dc9baf8
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Assets/Plugins/Editor/Uplift/UpliftPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,41 @@

namespace Uplift.Schemas
{
public partial class UpliftPreferences : MonoBehaviour
public partial class UpliftPreferences
{
public static readonly string folderName = ".uplift";
public static readonly string defaultFileName = "preferences.xml";

public static UpliftPreferences FromDefaultFile()
{
return FromFile(GetDefaultLocation());
UpliftPreferences result;
//if (TryLoadFromFile(GetProjectLocation(), out result))
// return result;
if (TryLoadFromFile(GetGlobalLocation(), out result))
return result;

return new UpliftPreferences();
}

public static string GetDefaultLocation()
public static string GetGlobalLocation()
{
string sourceDir = System.IO.Path.Combine(GetHomePath(), folderName);
return System.IO.Path.Combine(sourceDir, defaultFileName);
}

public static UpliftPreferences FromFile(string source)
public static string GetProjectLocation()
{
UpliftPreferences result = new UpliftPreferences();
throw new NotImplementedException();
}

public static bool TryLoadFromFile(string source, out UpliftPreferences result)
{
result = new UpliftPreferences();

if (!File.Exists(source))
{
Debug.Log("No local settings file detected at " + source);
return result;
Debug.Log("No preferences file at " + source);
return false;
}

StrictXmlDeserializer<UpliftPreferences> deserializer = new StrictXmlDeserializer<UpliftPreferences>();
Expand All @@ -66,10 +77,10 @@ public static UpliftPreferences FromFile(string source)
catch (InvalidOperationException)
{
Debug.LogError(string.Format("Global Override file at {0} is not well formed", source));
return result;
return false;
}

return result;
return true;
}
}

Expand Down

0 comments on commit dc9baf8

Please sign in to comment.