-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finally fixed startup crashes. It was a threading issue
- Loading branch information
Showing
19 changed files
with
334 additions
and
225 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.IO; | ||
|
||
namespace BTD6_Mod_Manager.Lib | ||
{ | ||
public class Serializer | ||
{ | ||
public static T LoadFromFile<T>(string filePath) where T : class | ||
{ | ||
if (!IsPathValid(filePath)) | ||
return null; | ||
|
||
string json = File.ReadAllText(filePath); | ||
if (String.IsNullOrEmpty(json)) | ||
return null; | ||
|
||
return JsonConvert.DeserializeObject<T>(json); | ||
} | ||
|
||
private static bool IsPathValid(string filePath) | ||
{ | ||
Guard.ThrowIfStringIsNull(filePath, "Can't load file, path is null"); | ||
if (!File.Exists(filePath)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Save any class to file. This is not done yet | ||
/// </summary> | ||
public static void SaveToFile<T>(T jsonObject, string savePath, bool overwriteExisting = true) where T : class | ||
{ | ||
Guard.ThrowIfStringIsNull(savePath, "Can't save file, save path is null"); | ||
CreateDirIfNotFound(savePath); | ||
string json = JsonConvert.SerializeObject(jsonObject, Formatting.Indented); | ||
|
||
bool keepOriginal = !overwriteExisting; | ||
StreamWriter serialize = new StreamWriter(savePath, keepOriginal); | ||
serialize.Write(json); | ||
serialize.Close(); | ||
} | ||
|
||
private static void CreateDirIfNotFound(string dir) | ||
{ | ||
FileInfo f = new FileInfo(dir); | ||
Directory.CreateDirectory(f.Directory.FullName); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> | ||
<package id="WindowsAPICodePack-Core" version="1.1.1" targetFramework="net472" /> | ||
<package id="WindowsAPICodePack-Shell" version="1.1.1" targetFramework="net472" /> | ||
</packages> |
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
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using BTD6_Mod_Manager.Lib.Game; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BTD6_Mod_Manager.IO | ||
{ | ||
public class FileIO : Lib.IO.FileIO | ||
{ | ||
public static string BrowseForGameDir(string windowTitle = "Browse for BloonsTD6 directory") | ||
{ | ||
return BrowseForDirectory(windowTitle, Environment.CurrentDirectory); | ||
} | ||
|
||
public static string AutoDetectGameDir() => AutoDetectGameDir(SessionData.currentGame); | ||
public static string AutoDetectGameDir(GameType gameType) | ||
{ | ||
return SteamUtils.GetGameDir(gameType); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.