private void UninstallDbMod(AuroraInstallation installation) { var uninstallScript = Path.Combine(DownloadPath, "uninstall.sql"); if (!File.Exists(uninstallScript)) { throw new Exception($"Db mod {Mod.Name} uninstall.sql not found at {DownloadPath}"); } using (var connection = new SqliteConnection(installation.ConnectionString)) { connection.Open(); var sql = "SELECT * FROM sqlite_master WHERE name ='A_THIS_SAVE_IS_MODDED' and type='table';"; var command = new SqliteCommand(sql, connection); var reader = command.ExecuteReader(); if (!reader.Read()) { reader.Close(); connection.Close(); Log.Debug($"Not attempting to uninstall {Mod.Name} since {sql} returned no rows"); return; } else { reader.Close(); } sql = $"SELECT * FROM A_THIS_SAVE_IS_MODDED WHERE ModName = '{Mod.Name}'"; command = new SqliteCommand(sql, connection); reader = command.ExecuteReader(); while (reader.Read()) { var name = reader[0].ToString(); if (name == null) { throw new Exception($"Installed db mod {Mod.Name} not found"); } else { sql = File.ReadAllText(uninstallScript); sql += $"\nDELETE FROM A_THIS_SAVE_IS_MODDED\nWHERE ModName = '{name}';"; command = new SqliteCommand(sql, connection); command.ExecuteNonQuery(); Log.Debug($"Uninstalled db mod: {name}"); } } reader.Close(); connection.Close(); } }
public void Uninstall(AuroraInstallation installation) { if (Mod.Type == ModType.THEME) { UninstallThemeMod(installation); } else if (Mod.Type == ModType.DATABASE) { UninstallDbMod(installation); } }
public void Install(AuroraInstallation installation) { Log.Debug($"{Mod.Type}: {Mod.Name} {Version}"); if (Mod.Type == ModType.DATABASE) { InstallDbMod(installation); } else if (Mod.Type == ModType.ROOTUTILITY || Mod.Type == ModType.EXECUTABLE || Mod.Type == ModType.THEME) { CopyToFolder(installation.InstallationPath); } }
private void UninstallThemeMod(AuroraInstallation installation) { foreach (var fileInMod in Directory.EnumerateFiles(DownloadPath, "*.*", SearchOption.AllDirectories)) { var out_file = Path.Combine(installation.InstallationPath, Path.GetRelativePath(DownloadPath, fileInMod)); if (File.Exists(out_file)) { File.Delete(out_file); } } Log.Debug($"Uninstalled theme mod: {Mod.Name}"); }
public Process Run(AuroraInstallation installation) { if (Mod.Type == ModType.UTILITY) { return(Run(DownloadPath, Mod.LaunchCommand)); } else if (Mod.Type == ModType.ROOTUTILITY || Mod.Type == ModType.EXECUTABLE) { return(Run(installation.InstallationPath, Mod.LaunchCommand)); } else { throw new InvalidOperationException($"{Mod.Type} does not support being run"); } }
private void InstallDbMod(AuroraInstallation installation) { const string TABLE = "CREATE TABLE IF NOT EXISTS A_THIS_SAVE_IS_MODDED (ModName Text PRIMARY KEY);"; using (var connection = new SqliteConnection(installation.ConnectionString)) { connection.Open(); var table = new SqliteCommand(TABLE, connection); table.ExecuteNonQuery(); var files = Directory.EnumerateFiles(DownloadPath, "*.sql").ToList(); try { var uninstall = files.Single(f => Path.GetFileName(f).Equals("uninstall.sql")); files.Remove(uninstall); } catch (Exception) { Log.Debug($"No uninstall for db mod: {Mod.Name}"); connection.Close(); throw new Exception($"No uninstall for db mod: {Mod.Name}"); } foreach (var file in files) { var sql = File.ReadAllText(file); var command = new SqliteCommand(sql, connection); command.ExecuteNonQuery(); sql = $"INSERT INTO A_THIS_SAVE_IS_MODDED(ModName)" + $"SELECT '{Mod.Name}'" + $"WHERE NOT EXISTS(SELECT 1 FROM A_THIS_SAVE_IS_MODDED WHERE ModName = '{Mod.Name}');"; command = new SqliteCommand(sql, connection); command.ExecuteNonQuery(); Log.Debug($"Installed db mod: {Mod.Name}"); } connection.Close(); } }
public void UpdateAurora_NoFilesSelected_NoFilesDownloaded() { var defaultAuroraInstallation = new AuroraInstallation(auroraVersion, installationPath); Assert.Throws <ArgumentException>(delegate { defaultAuroraInstallation.UpdateAurora(new Dictionary <string, string>()); }); }
public void UpdateAurora_NullFiles_ThrowsArgumentNullException() { var defaultAuroraInstallation = new AuroraInstallation(auroraVersion, installationPath); Assert.Throws <ArgumentNullException>(delegate { defaultAuroraInstallation.UpdateAurora(null); }); }
public void ConnectionString_DefaultInput_EqualsKnownString() { var defaultAuroraInstallation = new AuroraInstallation(auroraVersion, installationPath); Assert.That(defaultAuroraInstallation.ConnectionString, Is.EqualTo($"Data Source={Path.Combine(installationPath, "AuroraDB.db")}")); }