void ModManagement_DownloadFailed(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } CleanupDownload(); Locations.MessageBoxShow("Download Failed:\r\n\r\n" + e.Error.ToString() + "\r\n\r\nPlease manually download the file and select it.", MessageBoxButton.OK, MessageBoxImage.Error); ModConfiguration mod = e.UserState as ModConfiguration; if (string.IsNullOrEmpty(mod.Download.Source)) { System.Diagnostics.Process.Start(mod.Download.Source); } else { System.Diagnostics.Process.Start(mod.Download.Webpage); } BrowseForPackage(mod); if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
private void ToAndroid_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn != null) { ModConfiguration config = btn.CommandParameter as ModConfiguration; if (config != null) { Locations.MessageBoxShow(AMLResources.Properties.Resources.AttachAndroid, MessageBoxButton.OK, MessageBoxImage.Information); System.Windows.Forms.FolderBrowserDialog diag = new System.Windows.Forms.FolderBrowserDialog(); diag.Description = AMLResources.Properties.Resources.BrowseToFolder; if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Locations.CopyFiles(new System.IO.DirectoryInfo(config.InstalledPath), diag.SelectedPath, "*.snt"); Locations.CopyFiles(new System.IO.DirectoryInfo(config.InstalledPath), diag.SelectedPath, "*.xml"); Locations.MessageBoxShow( AMLResources.Properties.Resources.CopyComplete + DataStrings.CRCR + AMLResources.Properties.Resources.ApplyToAndroid, MessageBoxButton.OK, MessageBoxImage.Information); } } } }
public bool UninstallMod(string ID) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } ModConfiguration item = null; bool retVal = false; foreach (ModConfiguration config in Configurations) { if (config.ID == ID) { item = config; break; } } if (item != null) { retVal = UninstallMod(item); } else { retVal = false; } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
public bool UninstallMod(ModConfiguration mod) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } bool retVal = true; if (Configurations.Contains(mod)) { if (mod.UninstallMod()) { Configurations.Remove(mod); Save(); } else { retVal = false; } } else { retVal = false; } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
private void InstallFromWeb_Click(object sender, RoutedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } Button btn = sender as Button; if (btn != null) { ModConfiguration mod = btn.CommandParameter as ModConfiguration; if (mod != null) { bool NeedPackageSpecified = true; if (!string.IsNullOrEmpty(mod.Download.Source)) { StartDownload(mod); } else if (NeedPackageSpecified) { BrowseForPackage(mod); } } } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
public bool DeactivateStock() { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } bool retVal = true; if (Configurations.Count == 1) { ModConfiguration config = Configurations[0]; config.DeactivateMod(); Configurations.Remove(config); } else { retVal = false; if (Configurations.Count > 1) { throw new InvalidOperationException("Cannot deactivate Stock while other Mods are active."); } } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
public bool InstallMod(ModConfiguration mod, string source) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } bool retVal = false; if (ModAlreadyInstalled(mod.ID)) { retVal = false; } else { if (!VersionOK(source)) { return(false); } Locations.CreatePath(Locations.ArtemisCopyPath); string src = source; FileAttributes attr = File.GetAttributes(src); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingMod); mod.InstallMod(src); } else if (src.EndsWith("EXE", StringComparison.OrdinalIgnoreCase)) { ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingMod); InstallEXE(mod, src); } else { ModManagement.DoMessage(AMLResources.Properties.Resources.UnpackagingMod); src = mod.Unpackage(source); if (string.IsNullOrEmpty(src)) { return(false); } } this.Dispatcher.BeginInvoke(new Action <ModConfiguration>(AddToCollection), mod); retVal = true; } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
void StartDownload(ModConfiguration config) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } ModManagement.Downloaded += new EventHandler <System.ComponentModel.AsyncCompletedEventArgs>(ModManagement_Downloaded); ModManagement.DownloadFailed += new EventHandler <System.ComponentModel.AsyncCompletedEventArgs>(ModManagement_DownloadFailed); ModManagement.StartDownload(config); if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
public void AppendConfig(ModConfiguration config) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } if (!ModManagement.IsInstalled(config.ID)) { Definitions.Add(config); } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
static void UpdateProperties(ModConfiguration source, ModConfiguration target) { try { if (target.ID == source.ID) { } } catch (Exception ex) { if (_log.IsWarnEnabled) { _log.Warn("Exception updating config", ex); } } }
static void UpdateConfig(ModConfiguration installedConfig) { foreach (System.IO.FileInfo fle in new System.IO.DirectoryInfo(Locations.PredefinedModsPath).GetFiles()) { try { ModConfiguration config = new ModConfiguration(fle.FullName); UpdateProperties(config, installedConfig); } catch (Exception ex) { if (_log.IsWarnEnabled) { _log.Warn("Exception updating config", ex); } } } }
void ModManagement_Downloaded(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } CleanupDownload(); if (e != null) { ModConfiguration mod = e.UserState as ModConfiguration; ModManagement.InstallComplete += new EventHandler <ProcessEventArgs>(ModManagement_InstallComplete); ModManagement.BeginInstall(mod, mod.PackagePath); } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
private void ModUninstalled(object sender, RoutedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } //Only if a pre-defined mod. ModConfiguration mod = e.OriginalSource as ModConfiguration; if (ModManagement.GetPredefinedMods().ContainsKey(mod.ID)) { predefinedMods.AppendConfig(mod); } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
private void Browse_Click(object sender, RoutedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } Button btn = sender as Button; if (btn != null) { ModConfiguration mod = btn.CommandParameter as ModConfiguration; if (mod != null) { System.Diagnostics.Process.Start(mod.Download.Webpage); } } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
private void Activate_Click(object sender, RoutedEventArgs e) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } Button btn = sender as Button; if (btn != null) { ModConfiguration mod = btn.CommandParameter as ModConfiguration; if (mod != null) { ModManagement.Activate(mod); } } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
void BrowseForPackage(ModConfiguration mod) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } OpenFileDialog diag = new OpenFileDialog(); diag.Filter = AMLResources.Properties.Resources.SupportedCompressedFiles + DataStrings.SupportedCompressedFilesFilter + "|" + AMLResources.Properties.Resources.AllFiles + DataStrings.AllFilesFilter; diag.Title = Locations.AssemblyTitle; if (diag.ShowDialog() == true) { ModManagement.InstallComplete += new EventHandler <ProcessEventArgs>(ModManagement_InstallComplete2); ModManagement.BeginInstall(mod, diag.FileName); } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
public PredefinedMods() { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } Definitions = new ObservableCollection <ModConfiguration>(); List <string> predefined = new List <string>(); ModConfiguration config = null; PredefinedModDictionary.Clear(); try { foreach (System.IO.FileInfo fle in new System.IO.DirectoryInfo(Locations.PredefinedModsPath).GetFiles()) { config = new ModConfiguration(fle.FullName); PredefinedModDictionary.Add(config.ID, config); predefined.Add(config.ID); AppendConfig(config); } } catch (Exception ex) { if (_log.IsWarnEnabled) { _log.Warn("Error reading list of Pre-defined MODS.", ex); } } PreDefinedList = new ReadOnlyCollection <string>(predefined); InitializeComponent(); if (Definitions.Count < 1) { this.Visibility = System.Windows.Visibility.Collapsed; } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
public bool ActivateConfiguration(ModConfiguration config) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } bool retVal = true; if (!IsAlreadyActive(config.ID)) { config.ActivateMod(); config.Sequence = Configurations.Count; Configurations.Add(config); SaveData(); } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
public ModDefinitionSetup() { Configuration = new ModConfiguration(); InitializeComponent(); }
public bool DeactivateLastConfig() { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } bool retVal = true; if (Configurations.Count > 1) { ModConfiguration config = Configurations[Configurations.Count - 1]; if (_log.IsInfoEnabled) { _log.InfoFormat("~~~~~~~~~~~~~ Beginning Deactivation of {0}", config.Title); } config.DeactivateMod(); Configurations.Remove(config); for (int i = Configurations.Count - 1; i >= 0; i--) { foreach (FileMap m in Configurations[i].ActiveFiles) { if (!File.Exists(m.Target)) { if (File.Exists(m.Source)) { if (_log.IsInfoEnabled) { _log.InfoFormat("Restoring \"{0}\" from config {1}", m.Source, Configurations[i].Title); } File.Copy(m.Source, m.Target); } else { if (_log.IsWarnEnabled) { _log.WarnFormat("Source file is missing: \"{0}\"", m.Source); } //A source file from Mod "{0}" is missing. StringBuilder sb = new StringBuilder(); sb.AppendFormat(AMLResources.Properties.Resources.SourceNotFoundPrefix, Configurations[i].Title); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(AMLResources.Properties.Resources.CorruptedMod); sb.AppendLine(); sb.AppendLine(AMLResources.Properties.Resources.ProcessingContinue); sb.AppendLine(); sb.AppendFormat(AMLResources.Properties.Resources.MissingFileLabel, m.Source); Locations.MessageBoxShow(sb.ToString(), MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } //Processing base files might not be needed if bug with active files fixed. ////////if (Configurations[i].BaseFiles != null) ////////{ //////// foreach (FileMap m in Configurations[i].BaseFiles) //////// { //////// string target = Path.Combine(Locations.ArtemisCopyPath, m.Target); //////// if (m.Source.Contains("*") || m.Source.Contains("?")) //////// { //////// //more than one file, wildcarded. //////// string sourceFle = m.Source; //////// int i1 = sourceFle.LastIndexOf('\\'); //////// sourceFle = sourceFle.Substring(0, i1); //////// string fullSrc = Path.Combine(Configurations[i].InstalledPath, sourceFle); //////// foreach (FileInfo f in new DirectoryInfo(fullSrc).GetFiles("*.*", SearchOption.AllDirectories)) //////// { //////// string relative = f.DirectoryName.Substring(fullSrc.Length + 1); //////// if (relative.StartsWith("\\", StringComparison.OrdinalIgnoreCase)) //////// { //////// relative = relative.Substring(1); //////// } //////// if (!File.Exists(Path.Combine(Locations.ArtemisCopyPath, relative))) //////// { //////// f.CopyTo(Path.Combine(Locations.ArtemisCopyPath, relative)); //////// } //////// } //////// } //////// else //////// { //////// if (!File.Exists(target)) //////// { //////// string src = Path.Combine(Configurations[i].InstalledPath, m.Source); //////// if (File.Exists(src)) //////// { //////// File.Copy(src, target); //////// } //////// else //////// { //////// if (_log.IsWarnEnabled) //////// { //////// _log.WarnFormat("Source file is missing: \"{0}\"", src); //////// } //////// Locations.MessageBoxShow("A source file from Mod \"" //////// + Configurations[i].Title //////// + "\" is missing.\r\n\r\nThis could mean the mod is corrupted.\r\n\r\n" //////// + "Processing will continue, but you may want to deactivate this mod and re-install.\r\n\r\n" //////// + " Missing file: \"" + src + "\"", //////// MessageBoxButton.OK, MessageBoxImage.Exclamation); //////// } //////// } //////// } //////// } ////////} } //Do Save. SaveData(); } else { retVal = false; } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } return(retVal); }
private static void InstallEXE(ModConfiguration config, string file) { if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } if (string.IsNullOrEmpty(file) || !file.EndsWith(".EXE", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Must be an EXE file to call InstallEXE Method."); } if (config != null) { Locations.MessageBoxShow( AMLResources.Properties.Resources.EXEInstallWarning + DataStrings.CRCR + AMLResources.Properties.Resources.FullRestoreWarning, MessageBoxButton.OK, MessageBoxImage.Information); //First get list of files ModManagement.DoMessage(AMLResources.Properties.Resources.LoadingListOfFiles); #if EXETest string testPath = @"D:\Stuff\Downloads\Artemis backup"; FileInfo[] PreInstall = new DirectoryInfo(testPath).GetFiles("*.*", SearchOption.AllDirectories); #else FileInfo[] PreInstall = new DirectoryInfo(Locations.ArtemisInstallPath).GetFiles("*.*", SearchOption.AllDirectories); ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingModMessage); RunAdminProcess(file, string.Empty); #endif ModManagement.DoMessage(AMLResources.Properties.Resources.LoadingListAddedByMod); FileInfo[] PostInstall = new DirectoryInfo(Locations.ArtemisInstallPath).GetFiles("*.*", SearchOption.AllDirectories); if (VersionOK(Locations.ArtemisInstallPath)) { //Now identify what changed, and copy changed files to work path. string wrkPath = Path.Combine(Locations.InstalledModsPath, config.ID); if (_log.IsInfoEnabled) { _log.InfoFormat("Work Path set to \"{0}\"", wrkPath); } Dictionary <string, FileInfo> PreInstallFiles = new Dictionary <string, FileInfo>(); foreach (FileInfo f in PreInstall) { string fn = f.FullName; #if EXETest fn = fn.Replace(testPath, Locations.ArtemisInstallPath); #endif PreInstallFiles.Add(fn, f); } ModManagement.DoMessage(AMLResources.Properties.Resources.CopyingToModInstallation); foreach (FileInfo f in PostInstall) { if (_log.IsInfoEnabled) { _log.InfoFormat("Post install file: {0}", f.FullName); } string relative = f.DirectoryName.Substring(Locations.ArtemisInstallPath.Length); if (relative.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { relative = relative.Substring(0, relative.Length - 1); } if (relative.StartsWith("\\", StringComparison.OrdinalIgnoreCase)) { relative = relative.Substring(1, relative.Length - 1); } string folder = Path.Combine(wrkPath, relative); if (_log.IsInfoEnabled) { _log.InfoFormat("Relative path = \"{1}\". Target folder set to \"{0}\"", folder, relative); } if (PreInstallFiles.ContainsKey(f.FullName)) { if (_log.IsInfoEnabled) { _log.Info("File found amoung preinstall."); } if (f.Length != PreInstallFiles[f.FullName].Length || f.LastWriteTimeUtc.CompareTo(PreInstallFiles[f.FullName].LastWriteTimeUtc) != 0) { if (_log.IsInfoEnabled) { _log.Info("File size or last modified date not match."); } DoCopy(folder, f); } else { if (_log.IsInfoEnabled) { _log.Info("File matches perfectly."); } } } else { if (_log.IsInfoEnabled) { _log.Info("File was not found among pre-installed files."); } DoCopy(folder, f); } } } #if !EXETest if (!string.IsNullOrEmpty(config.Uninstall)) { ModManagement.DoMessage(AMLResources.Properties.Resources.UninstallingEXEMod); RunAdminProcess(Path.Combine(Locations.ArtemisInstallPath, config.Uninstall), string.Empty); System.Threading.Thread.Sleep(10000); } else { Locations.MessageBoxShow( AMLResources.Properties.Resources.PleaseRunUninstaller, MessageBoxButton.OK, MessageBoxImage.Exclamation); } ModManagement.DoMessage(AMLResources.Properties.Resources.RestoringOriginalArtemis); // config.InstallMod(wrkPath); ModConfiguration stock = new ModConfiguration(Locations.MODStockDefinition); string StockPath = Path.Combine(Locations.InstalledModsPath, stock.ID); string xcopy = Path.Combine(Path.GetTempPath(), DataStrings.RestoreArtemisCmd); using (StreamWriter sw = new StreamWriter(xcopy)) { sw.WriteLine(string.Format(DataStrings.XcopyCommand, StockPath, Locations.ArtemisInstallPath)); } RunAdminProcess(xcopy, string.Empty); #endif } if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } }
void AddToCollection(ModConfiguration mod) { Configurations.Add(mod); this.Save(); }
public ProcessEventArgs(bool result, ModConfiguration config) { Result = result; Configuration = config; }