Skip to content

Commit

Permalink
config fix, data integrity
Browse files Browse the repository at this point in the history
adding locally compiled adds to config file
mods not in config will not be loaded
mods that are missing files get re-downloaded
  • Loading branch information
Rynchodon committed Apr 29, 2017
1 parent dade9d1 commit 7dfef99
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Injector/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.5.0")]
[assembly: AssemblyVersion("0.5.6.0")]
53 changes: 51 additions & 2 deletions Loader/LoadArms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private LoadArms(bool start)

Logger.logFile = _directory + (Game.IsDedicated ? "Load-ARMS Dedicated.log" : "Load-ARMS.log");
Logger.WriteLine("Load-ARMS version: " + new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location), 0));

if (start)
_task = ParallelTasks.Parallel.StartBackground(Run);
}
Expand All @@ -210,6 +210,7 @@ private void Run()
{
Cleanup();
Load();
VerifyDataIntegrity();
UpdateMods();
SaveData();
}
Expand Down Expand Up @@ -358,6 +359,28 @@ private void LoadData()
SaveData();
}

/// <summary>
/// Check for mod files that got deleted.
/// </summary>
private void VerifyDataIntegrity()
{
List<int> removals = new List<int>();
foreach (var mod in _data.ModsCurrentVersions)
if (mod.Value.MissingFiles())
{
Logger.WriteLine(mod.Value.fullName + " is missing files, removing");
mod.Value.EraseAllFiles();
removals.Add(mod.Key);
}

if (removals.Count != 0)
{
foreach (int key in removals)
_data.ModsCurrentVersions.Remove(key);
SaveData();
}
}

private void SaveConfig()
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Config));
Expand Down Expand Up @@ -417,11 +440,36 @@ private List<IPlugin> LoadPlugins()
List<IPlugin> chainedPlugins = new List<IPlugin>();

foreach (ModVersion mod in _data.ModsCurrentVersions.Values)
LoadPlugins(chainedPlugins, mod, loadedMods);
if (InConfig(mod))
LoadPlugins(chainedPlugins, mod, loadedMods);
else
Logger.WriteLine("Not loading " + mod.fullName + ", not in config");

return chainedPlugins;
}

private bool InConfig(ModName name)
{
for (int index = _config.GitHubMods.Length - 1; index >= 0; --index)
if (_config.GitHubMods[index].fullName == name.fullName)
return true;
return false;
}

private void EnsureInConfig(ModName name)
{
if (InConfig(name))
return;

Logger.WriteLine("Adding " + name.fullName + " to config file");
ModInfo[] newArray = new ModInfo[_config.GitHubMods.Length + 1];
_config.GitHubMods.CopyTo(newArray, 0);
newArray[newArray.Length - 1] = new ModInfo(name, true);
_config.GitHubMods = newArray;

SaveConfig();
}

private bool LoadPlugins(List<IPlugin> chainedPlugins, ModVersion mod, HashSet<ModVersion> loadedMods, int depth = 0)
{
if (mod.author == Rynchodon && mod.repository == LoadArmsRepo)
Expand Down Expand Up @@ -534,6 +582,7 @@ private ModVersion AddLocallyCompiled(ModName name, Version version, int seVersi
current.filePaths = copied.ToArray();
current.locallyCompiled = true;

EnsureInConfig(current);
SaveData();

if (name.author == Rynchodon && name.repository == LoadArmsRepo)
Expand Down
21 changes: 21 additions & 0 deletions Loader/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ internal class ModInfo : ModName
[DataMember]
public bool downloadPrerelease;
#pragma warning restore CS0649

public ModInfo() { }

public ModInfo(ModName name, bool downloadPrerelease)
{
this.author = name.author;
this.repository = name.repository;
this.downloadPrerelease = downloadPrerelease;
}
}

/// <summary>
Expand Down Expand Up @@ -103,5 +112,17 @@ public void EraseAllFiles()

filePaths = null;
}

public bool MissingFiles()
{
if (filePaths == null)
return false;

foreach (string filePath in filePaths)
if (!File.Exists(filePath))
return true;

return false;
}
}
}

0 comments on commit 7dfef99

Please sign in to comment.