/// <summary> /// Fonction d'effacement des fichiers /// </summary> /// <param name="selectedItems"></param> /// <param name="basePath"></param> private void DeleteFiles(ListBox.SelectedObjectCollection selectedItems, string basePath) { foreach (string file in selectedItems) { if (OPFiles.SendTo_Recycle(file, Path.Combine(basePath, file))) { MessageBox.Show($"File: '{file}' deleted."); } else { MessageBox.Show($"Error, File: '{file}' not deleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static GameInfo InfoGame(string path, Game zeGame) { ITrace.WriteLine(prefix: false); ITrace.WriteLine($"[MakeInfo] Creation of file 'Infos.xml'"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string xmlDest = Path.Combine(path, "Infos.xml"); var infoRes = OPFiles.SingleVerif(xmlDest, "InfoGame", Dcs_Buttons.NoRename, log: (string message) => ITrace.WriteLine(message, true)); switch (infoRes) { case EOPResult.NotExisting: case EOPResult.OverWrite: case EOPResult.Trashed: ITrace.WriteLine("[InfoGame] Serialization to xml"); try { XmlSerializer xs = new XmlSerializer(typeof(GameInfo)); using (StreamWriter wr = new StreamWriter(xmlDest)) { xs.Serialize(wr, zeGame); } return(true); } catch (Exception exc) { ITrace.WriteLine(exc.ToString()); return(false); } default: return(false); } }
/// <summary> /// /// </summary> /// <param name="folder2Comp">Dossier à compresser</param> /// <param name="path">Chemin de stockage de l'archive</param> /// <param name="gameName">Lien vers </param> /// <returns></returns> public static bool Make_Folder(string folder2Comp, string path, string gameName) { /* #region 2020 choix du nom * * GameName gnWindows = new GameName(); * gnWindows.SuggestedGameName = gameName; * gnWindows.ShowDialog(); * * //string destArchLink = Path.Combine(path, $"{destArchive}"); * string destArchLink = Path.Combine(path, gnWindows.ChoosenGameName); * #endregion */ string destArchLink = Path.Combine(path, gameName); //string destArchLink = Path.Combine(path, $"{destArchive}.7z"); //string destArchLink = Path.Combine(path, $"{destArchive}.zip"); var zipRes = OPFiles.SingleVerif(destArchLink, "Make_Zip", log: (string message) => ITrace.WriteLine(message, true)); switch (zipRes) { case EOPResult.OverWrite: case EOPResult.NotExisting: case EOPResult.Trashed: if (!ZipCompression.CompressFolder(folder2Comp, destArchLink, Properties.Settings.Default.cZipCompLvl)) { ITrace.WriteLine("[Make_Zip] Zip Compression canceled"); return(false); } ITrace.WriteLine($"[Make_Zip] Zip Compression begin"); return(true); default: return(false); } }
/// <summary> /// Copie les cheatcodes / Copy all cheatcodes /// </summary> private void CopyCheatCodes() { string CCodesDir = Path.Combine(Properties.Settings.Default.CCodesPath, _SystemName); ITrace.BeginLine($"[CopyCheatCodes] Search in: '{CCodesDir}' of files beginning by '{_ZeGame.Title}-': "); if (!Directory.Exists(CCodesDir)) { return; } string usableT = _ZeGame.Title.Replace(":", "-"); string[] fichiers = Directory.GetFiles(CCodesDir, usableT, System.IO.SearchOption.AllDirectories); ITrace.EndlLine($"{fichiers.Length} found"); OPFiles opF = new OPFiles() { WhoCallMe = "CheatCodes", Buttons = Dcs_Buttons.NoStop, }; opF.IWriteLine += (string message) => ITrace.WriteLine(message); opF.IWrite += (string message) => ITrace.BeginLine(message); // foreach (string file in fichiers) { // TODO URGENCE //21/10/2020 //var cheatCodeRes = opF.FileNameCompare(file, _Tree.Children[nameof(SubFolder.CheatCodes)].Path); //CopyFile(file, _Tree.Children[nameof(SubFolder.CheatCodes)].Path, cheatCodeRes); Copy_Handler(file, _Tree.Children[nameof(SubFolder.CheatCodes)].Path, "Cheats"); //21/10/2020 } }
/// <summary> /// Copie les clones / Clones copy /// </summary> private void CopyClones() { ITrace.WriteLine(prefix: false); OPFiles opF = new OPFiles() { Buttons = Dcs_Buttons.NoStop, WhoCallMe = "Clone" }; opF.IWriteLine += (string message) => ITrace.WriteLine(message); opF.IWrite += (string message) => ITrace.BeginLine(message); List <Clone> clones = new List <Clone>(); _XFunctions.ListClones(clones, _ZeGame.ID); // tri des doublons / filter duplicates List <Clone> fClones; //fClones= clones.Distinct().ToList(); fClones = FilesFunc.DistinctClones(clones, _ZeGame.FileName); // On va vérifier que chaque clone n'est pas déjà présent et selon déjà copier foreach (Clone zeClone in fClones) { zeClone.ApplicationPath = ReconstructPath(zeClone.ApplicationPath); /* 20/10/2020 * var cloneRes = opF.FileNameCompare(zeClone.ApplicationPath, _Tree.Children[nameof(SubFolder.Roms)].Path); * CopyFile(zeClone.ApplicationPath, _Tree.Children[nameof(SubFolder.Roms)].Path, cloneRes); */ Copy_Handler(zeClone.ApplicationPath, _Tree.Children[nameof(SubFolder.Roms)].Path, "Roms"); } }
/// <summary> /// Conversion des données du jeu en xml tb/eb /// </summary> /// <param name="path"></param> /// <param name="zeGame"></param> /// <param name="title"></param> /// <returns></returns> public static bool Backup_Game(string path, Game zeGame, string title) { ITrace.WriteLine(prefix: false); ITrace.WriteLine($"[MakeInfo] Creation of file '{title}.xml'"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string xmlDest = Path.Combine(path, $"{title}.xml"); var infoRes = OPFiles.SingleVerif(xmlDest, "Backup_Game", Dcs_Buttons.NoRename, log: (string message) => ITrace.WriteLine(message, true)); switch (infoRes) { case EOPResult.NotExisting: case EOPResult.OverWrite: case EOPResult.Trashed: /*try * {*/ ITrace.WriteLine("[Backup_Game] Serialization to xml"); XmlSerializer xGame = new XmlSerializer(typeof(Game)); XmlSerializer xLCFields = new XmlSerializer(typeof(CustomField)); XmlSerializer xLAApp = new XmlSerializer(typeof(AdditionalApplication)); //////using (StreamWriter wr = new StreamWriter(xmlDest, false)) //////{ ////// xGame.Serialize(wr, zeGame, null); ////// foreach (var cFields in zeGame.CustomFields) xLCFields.Serialize(wr, cFields, null); ////// foreach (var aApp in zeGame.AdditionalApplications) xLAApp.Serialize(wr, aApp, null); //////} XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; // remove declaration xws.Indent = true; xws.ConformanceLevel = ConformanceLevel.Auto; using (XmlWriter xw = XmlWriter.Create(xmlDest, xws)) { var xmlns = new XmlSerializerNamespaces(); // Remove xml namespaces xmlns.Add("", ""); xw.WriteStartElement("LaunchBox_Backup"); xw.WriteComment("Put this between <LaunchBox> </LaunchBox> in 'platform'.xml (try to organize it)"); xGame.Serialize(xw, zeGame, xmlns); xw.WriteComment("For the roms files it represents clones, trainers..."); foreach (var aApp in zeGame.AdditionalApplications) { xLAApp.Serialize(xw, aApp, xmlns); } xw.WriteComment("It's the custom fields that you can create in Launchbox)"); foreach (var cFields in zeGame.CustomFields) { xLCFields.Serialize(xw, cFields, xmlns); } xw.WriteEndElement(); } return(true); /*} * catch (Exception exc) * { * ITrace.WriteLine(exc.ToString()); * //return false; * ITrace.WriteLine(exc.Message); * return false; * }*/ default: return(false); } }
/// <summary> /// Gère la copie en examinant la totale similitude des fichiers /// </summary> /// <param name="srcFile"></param> /// <param name="destLocation"></param> /// <param name="mediatype"></param> private bool Copy_Handler(string srcFile, string destLocation, string mediatype) { // 2020 // Test de la similitude en profondeur //FilesFunc.Check4Crash(); OPFiles neoOPF = new OPFiles() { }; neoOPF.IWrite += new RetourMessage((x) => ITrace.BeginLine(x)); neoOPF.IWriteLine += new RetourMessage((x) => ITrace.WriteLine(x)); // Booleen pour déterminer si l'on écrase ou pas bool overW = false; // Vérification en profondeur // Annulé EOPResult res = OPFiles.Copy_DeepVMode(dbPath, destLocation, $"Copy_{mediatype}", () => MD5.Create(), Dcs_Buttons.NoStop, x => ITrace.WriteLine(x)); string fileName = Path.GetFileName(srcFile); string destFile = Path.Combine(destLocation, fileName); EFileResult verif = neoOPF.DeepVerif(srcFile, destFile, () => MD5.Create()); bool copyRes = false; // Stocke le résultat de la copie switch (verif) { case EFileResult.DifferentSize: case EFileResult.DifferentHash: // Check selon les résultats de ce qu'il faut faire // Demande à l'utilisateur // EDestDecision res = MB_Decision.Show($"Copy_Handler: {Lang.Dest_File_Exists}, { Lang.Replace_Question} ?", $"{Lang.Alert} - Copy_Handler", destination: destLocation, buttons: Dcs_Buttons.All); EDestDecision res = MB_Decision.Show($"Copy_Handler: {Lang.Dest_File_Exists}, { Lang.Replace_Question} ?", $"{Lang.Alert} - Copy_Handler", source: srcFile, destination: destFile, buttons: Dcs_Buttons.All); // On passe si l'utilisateur ne veut pas écraser ou renommer /*if (res == EDestDecision.Pass || res == EDestDecision.PassAll) * return; */ // On utilise une fonction de traitement sur le fichier de destination (renommer, envoyer à la poubelle) neoOPF.DestFileAction(res, destFile); // Selon le résultat de la boite on copie ou non le fichier bool?overwrite = Handle_Copy(srcFile, ref destFile, res); if (overwrite != null) { copyRes = FilesFunc.Copy(srcFile, destFile, (bool)overwrite); } break; // Gère si la source a une taille 0 (entre autre) case EFileResult.Source_Error: break; case EFileResult.Destination_Error: case EFileResult.NoMatch: ITrace.WriteLine($"PackMe: Copy of '{fileName}'"); copyRes = FilesFunc.Copy(srcFile, destFile, false); break; default: ITrace.WriteLine($"PackMe: Copy of '{fileName}' avoided"); break; } return(copyRes); // 2020 //2020 EOPResult res = OPFiles.FileNameCompare(dbPath, destLocation, $"Copy_{mediatype}", Dcs_Buttons.NoStop, x => ITrace.WriteLine(x)); // assignation du chemin relatif à la variable // return CopyFile(dbPath, destLocation, res); }