public void TroveUriInstallModPack(string uri) { log.InfoFormat("Installing mod pack: [{0}] from Trove URI argument", uri); TroveModPack pack = new TroveModPack(uri); TroveModPackViewModel packVm = null; if (string.IsNullOrEmpty(pack.PackId)) { // Install Ad Hoc mod pack packVm = new TroveModPackViewModel(pack); ModPacks.Add(packVm); } else { // Find Trovesaurus mod pack packVm = ModPacks.FirstOrDefault(p => p.DataObject.PackId == pack.PackId); if (packVm == null) { log.ErrorFormat("Could not find Trovesaurus mod pack ID {0}", pack.PackId); return; } } ModPacksView.MoveCurrentTo(packVm); LoadModPack(packVm); }
private void SaveModPacks(object sender = null, PropertyChangedEventArgs e = null) { if (canSaveData) { SettingsDataProvider.MyModPacks = ModPacks.Where(p => p.DataObject.Source == TroveModPack.LocalSource).Select(p => p.DataObject).ToList(); } }
private void RemoveModPack(TroveModPackViewModel currentItem) { log.InfoFormat("Removing mod pack: {0}", currentItem.DataObject.Name); foreach (var mod in MyMods.Where(m => m.ModPack == currentItem)) { mod.ModPack = null; mod.DataObject.PackName = null; } ModPacks.Remove(currentItem); }
public DesignTimeMyModsViewModel() : base() { TroveModPackViewModel pack = new TroveModPackViewModel(new TroveModPack { Name = "Design Time Pack", Author = "Dazo" }); foreach (TroveMod mod in JsonConvert.DeserializeObject <List <TroveMod> >(Resources.DesignTimeTroveMods)) { MyMods.Add(new TroveModViewModel(mod)); pack.DataObject.Mods.Add(mod); } ModPacks.Add(pack); }
private void SaveModPack(string modPackName) { bool newPack = false; if (string.IsNullOrEmpty(modPackName)) { log.Warn("No mod pack name specified to save"); return; } log.InfoFormat("Saving enabled standalone mods as mod pack {0}", modPackName); TroveModPackViewModel pack = ModPacks.FirstOrDefault(p => p.DataObject.Name == modPackName && p.DataObject.Source == TroveModPack.LocalSource); if (pack == null) { pack = new TroveModPackViewModel(new TroveModPack()); pack.DataObject.Name = modPackName; newPack = true; } else { pack.DataObject.Mods.Clear(); } foreach (var mod in MyMods.Where(m => m.DataObject.Enabled && m.ModPack == null)) { if (string.IsNullOrEmpty(mod.DataObject.Id)) { log.WarnFormat("Only mods downloaded from Trovesaurus can be included in mod packs, skipping mod: {0}", mod.DisplayName); continue; } mod.ModPack = pack; mod.DataObject.PackName = modPackName; pack.DataObject.Mods.Add(mod.DataObject); } if (pack.DataObject.Mods.Count > 0) { if (newPack) { ModPacks.Add(pack); } ModPacksView.MoveCurrentTo(pack); } else { log.ErrorFormat("No enabled standalone mods from Trovesaurus were added to mod pack {0}", modPackName); } }
//écrit le fichier d'information pour chaque modpack (sera écrit dans un fichier nommé version.txt) //entrées: path: chemin du DOSSIER dans lequel écrire le fichier // struc: object qui contient les informations du modpack private void PrintVersion(string path, ModPacks struc) { try { string[] data = new string[1]; data[0] = struc.Nom; data[1] = struc.Version; File.WriteAllLines(path + "version.txt", data); } catch (Exception e) { if (this.Dispatcher.CheckAccess()) { Debug("Erreur dans l'écriture de la version\n" + e.ToString()); } else { Debug2("Erreur dans l'écriture de la version\n" + e.ToString()); } } }
//code principal backgroundworker private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { //modpack que l'on shouaite lancer pak = (ModPacks)e.Argument; //ClientVersion: version du modpack côté client //SrvVersion: version du modpack sur le serveur string ClientVersion, SrvVersion; //path: chemin relatif du modpack (par rapport au dossier instances) string Path = pak.Path; //InstancePath: chemin absolu du modpack string InstancePath = InstancesPath() + pak.Path; //contenu du fichier version.txt string data; this.Dispatcher.Invoke(() => { PB_Progress.IsIndeterminate = true; }); //récupère la version du modpack côté client, si elle existe. sinon met -1 if (File.Exists(InstancePath + "\\version.txt")) { data = File.ReadAllText(InstancePath + "\\version.txt"); var isNumeric = int.TryParse(data, out int n); if (isNumeric) { ClientVersion = data; } else { ClientVersion = "-1"; } } else { ClientVersion = "-1"; } if (!InternetAccess && pak.Version == "-1") { MessageBox.Show("impossible de lancer le modpack car ce dernier n'est pas complet."); Debug2("impossible de lancer le modpack car ce dernier n'est pas complet."); error = true; return; //dans le cas ou internet n'est pas accessible et que le internet n'est pas dispo, on quite la fonction. } SrvVersion = pak.Version; this.Dispatcher.Invoke(() => { PB_Progress.IsIndeterminate = false; }); //si la version serveur et client sont identique, on quite la fonction pour lancer le jeu. if (ClientVersion == SrvVersion) { return; //quite la fonction } if (InternetAccess) { try { Debug2("Connection SFTP"); using (Session session = new Session()) //note: il n'y a pas besoin de demander explicitement de fermer la connection car la sorti de using le fait automatiquement { //event que winscp déclenche lorsqu'il y a du progret dans le téléchargement session.FileTransferProgress += Session_FileTransferProgress; //Connection session.Open(sessionOptions); Debug2("Téléchargement modpack"); if (pak.Folders != null) { ct = 0; ctmax = pak.Folders.Length; foreach (JValue a in pak.Folders) { string i; i = a.ToString(); Debug2("Début téléchargement dossier: from [" + InstanceSrvPath + Path + "/" + i + "] to [" + InstancePath + "\\" + i.Replace("/", "\\") + "]"); if (!Directory.Exists(InstancePath + "\\" + i.Replace("/", "\\"))) { Directory.CreateDirectory(InstancePath + "\\" + i.Replace("/", "\\")); } session.SynchronizeDirectories(SynchronizationMode.Local, InstancePath + "\\" + i.Replace("/", "\\") + "\\", InstanceSrvPath + Path + "/" + i + "/", true, true); ct++; } } else { Debug2("pas de dossier définie en MAJ"); } if (pak.Files != null) { ct = 0; ctmax = pak.Files.Length; foreach (JValue a in pak.Files) { string i; i = a.ToString(); Debug2("Début téléchargement fichier: from [" + InstanceSrvPath + Path + "/" + i + "] to [" + InstancePath + "\\" + i.Replace("/", "\\") + "]"); if (session.FileExists(InstanceSrvPath + Path + "/" + i)) { RemoteFileInfo fichier = session.GetFileInfo(InstanceSrvPath + Path + "/" + i); if (fichier.LastWriteTime > File.GetLastWriteTime(InstancePath + "\\" + i.Replace("/", "\\"))) { session.GetFiles(InstanceSrvPath + Path + "/" + i, InstancePath + "\\" + i.Replace("/", "\\")); } else { Debug2("skipped (version local plus récente ou version serveur inchangé)"); } } else { Debug2("fichier absent coté serveur (" + i + ")"); } ct++; } } else { Debug2("pas de fichier définie en MAJ"); } File.WriteAllText(InstancePath + "\\version.txt", pak.Version); } } catch (Exception f) { MessageBox.Show("Erreur lors du téléchargement des fichiers \n" + f.ToString()); Debug2("Erreur lors du téléchargement des fichiers \n" + f.ToString()); error = true; } } else { if (!File.Exists(InstancePath + "\\run.bat")) { MessageBox.Show("pas de fichier executable pour le modpack"); Debug2("pas de fichier executable pour le modpack (run.bat not found at " + InstancePath + "\\run.bat" + ")"); error = true; } } }
public void LoadData() { // Load data and setup saving MyMods list to settings canSaveData = false; try { log.Info("Loading my mods"); // Load mods from model and create view model objects foreach (TroveMod mod in TroveMod.MyMods) { dynamic modVM = new TroveModViewModel(mod); MyMods.Add(modVM); modVM.CheckForUpdates(); } // Load local mod packs foreach (TroveModPack pack in SettingsDataProvider.MyModPacks) { ModPacks.Add(new TroveModPackViewModel(pack)); } // Load mod packs from Trovesaurus API foreach (TroveModPack pack in TrovesaurusApi.ModPackList) { ModPacks.Add(new TroveModPackViewModel(pack)); } // If auto update setting is enabled, update all mods on startup if (MainWindowViewModel.Instance.Settings.AutoUpdateMods) { UpdateAllMods(); StartUpdateTimer(SettingsDataProvider.AutoUpdateInterval); } // Setup auto-saving of my mods when the collection or items in the collection change MyMods.CollectionChanged += (s, e) => { if (e.OldItems != null) { foreach (INotifyPropertyChanged item in e.OldItems) { item.PropertyChanged -= SaveMyMods; } } if (e.NewItems != null) { foreach (INotifyPropertyChanged item in e.NewItems) { item.PropertyChanged += SaveMyMods; } } SaveMyMods(); }; // Setup auto-saving of mod packs when the collection or items in the collection change ModPacks.CollectionChanged += (s, e) => { SaveModPacks(); }; canSaveData = true; SaveMyMods(); SaveModPacks(); log.Info("Loaded my mods"); } catch (Exception ex) { log.Error("Error loading my mods", ex); } finally { canSaveData = true; } }