/// <summary> /// Initializes a new instance of the Controler class /// </summary> public MFControler() { InitDataBase(); _currentNDSRom = null; _currentGridViewName = string.Empty; _filters.ChangeFilter += new ChangeFilterEventHandler(F_ChangeFilter); }
/// <summary> /// Set Duplicate filter /// </summary> /// <param name="sender">sender</param> /// <param name="e">EventArgs</param> private void BtnFilterDuplicate_Click(object sender, EventArgs e) { NDS_Rom currentRom = _controler.GetCurrentRom(); string tabname = string.Format("{0} #{1}", Parameter.Lang.GetTranslate("TabFilterLocation"), currentRom.RomNumber); TabPage tab = tabControl2.TabPages[3]; tab.Show(); tab.Name = tabname; /* * if (_controler.IsDuplicateFilterActive()) * { * _controler.SetNoDuplicateFilter(); * btnFilterDuplicate.Text = Parameter.Lang.GetTranslate("btnFilterDuplicate_Apply"); * } * else * { * _controler.SetDuplicateFilterFromCurrentRom(); * btnFilterDuplicate.Text = Parameter.Lang.GetTranslate("btnFilterDuplicate_Reset"); * } * * _controler.SetCurrentGridView(string.Empty); * SetDataSource(); */ }
/// <summary> /// IntegrationArchive /// </summary> /// <param name="archive">archive</param> /// <param name="adata">ArchiveFileInfo</param> private void IntegrationArchive(string archive, ArchiveFileInfo adata) { string sevenZipCRC = adata.Crc.ToString("X"); while (sevenZipCRC.Length != 8) { sevenZipCRC = string.Format("0{0}", sevenZipCRC); } NDS_Rom romInfo = DataAcessLayer.FindCRCDataBase(sevenZipCRC.ToUpper()); if (romInfo != null) { if (!DataAcessLayer.IsCRCInCollection(sevenZipCRC.ToUpper())) { SevenZipExtractor szip = new SevenZipExtractor(archive); szip.Extracting += new EventHandler <ProgressEventArgs>(Szip_Extracting); szip.ExtractionFinished += new EventHandler <EventArgs>(Szip_ExtractionFinished); szip.FileExtractionStarted += new EventHandler <FileInfoEventArgs>(Szip_FileExtractionStarted); szip.ExtractFiles(Parameter.Config.Paths.DirTemp, new int[] { adata.Index }); NdsFileIntegration(string.Format("{0}{1}", Parameter.Config.Paths.DirTemp, adata.FileName), sevenZipCRC); } else { RomInCollection(romInfo, archive); } } else { RomNotFound(archive, sevenZipCRC); } }
/// <summary> /// RomInCollection /// </summary> /// <param name="romInfo">rom</param> /// <param name="file">file</param> private void RomInCollection(NDS_Rom romInfo, string file) { tos.SetIntituleTraitement(string.Format("Already have {0} ({1}) => This will not be integrated.", romInfo.Title, romInfo.RomNumber)); tos.SetRomInfo(romInfo); tos.SetRomInfoIntegration(TypeAvancement.RomAlreadyHave, Path.GetFileName(file)); ReportProgress(tos.Avance(TypeAvancement.RomAlreadyHave), tos); File.Move(file, Parameter.Config.Paths.DirAlreadyHave + Path.GetFileName(file)); }
/// <summary> /// Recalculate the collection and write it /// </summary> public static void RepairCollection() { // foreach (NDS_Rom rom in _ndsCollection.DataBase) for (int i = 0; i < _ndsCollection.NdsDataBase.Count; i++) { NDS_Rom romDB = FindCRCDataBase(_ndsCollection.NdsDataBase[i].RomCRC); if (romDB != null) { _ndsCollection.NdsDataBase[i] = romDB; } } SaveCollectionXML(); }
/// <summary> /// Load Informations about rom from AdvanScene xml /// </summary> /// <param name="xnd">XmlNode form AdvanScene xml</param> private void ChargeRomInfo(XmlNode xnd) { NDS_Rom rom = new NDS_Rom(); foreach (XmlNode xndd in xnd.ChildNodes) { switch (xndd.Name) { case "imageNumber": rom.ImageNumber = xndd.InnerText; if (int.Parse(xndd.InnerText) < 1000) { rom.ImageNumber = "0" + xndd.InnerText; } if (int.Parse(xndd.InnerText) < 100) { rom.ImageNumber = "00" + xndd.InnerText; } if (int.Parse(xndd.InnerText) < 10) { rom.ImageNumber = "000" + xndd.InnerText; } break; case "releaseNumber": rom.ReleaseNumber = xndd.InnerText; if (int.Parse(xndd.InnerText) < 1000) { rom.ReleaseNumber = "0" + xndd.InnerText; } if (int.Parse(xndd.InnerText) < 100) { rom.ReleaseNumber = "00" + xndd.InnerText; } if (int.Parse(xndd.InnerText) < 10) { rom.ReleaseNumber = "000" + xndd.InnerText; } break; case "title": rom.Title = xndd.InnerText; break; case "saveType": rom.SaveType = xndd.InnerText; break; case "romSize": rom.RomSize = (int.Parse(xndd.InnerText) / 1024 / 1024).ToString() + " Mo"; break; case "publisher": rom.Publisher = xndd.InnerText; break; case "location": rom.Location = LocationXML.GetStringLocation(int.Parse(xndd.InnerText)); break; case "sourceRom": rom.SourceRom = xndd.InnerText; break; case "language": rom.LanguageString = LanguageXML.GetLanguage(int.Parse(xndd.InnerText)); rom.LanguageCode = LanguageXML.GetLanguagesList(int.Parse(xndd.InnerText)); break; case "files": rom.RomCRC = xndd.ChildNodes[0].InnerText; break; case "im1CRC": rom.ImgCoverCRC = xndd.InnerText; break; case "im2CRC": rom.ImgInGameCRC = xndd.InnerText; break; case "nfoCRC": rom.NfoCRC = xndd.InnerText; break; case "icoCRC": rom.IcoCRC = xndd.InnerText; break; case "genre": rom.Genre = xndd.InnerText; break; case "dumpdate": rom.DumpDate = DateTime.Parse(xndd.InnerText); break; case "internalname": rom.InternalName = xndd.InnerText; break; case "serial": rom.Serial = xndd.InnerText; break; case "version": rom.Version = xndd.InnerText; break; case "wifi": switch (xndd.InnerText) { case "No": rom.Wifi = false; break; case "Yes": rom.Wifi = true; break; default: break; } break; case "comment": rom.RomNumber = xndd.InnerText; break; case "duplicateid": if (xndd.InnerText == "0") { rom.DuplicateID = 0; } else { rom.DuplicateID = int.Parse(xndd.InnerText); } break; case "dirname": rom.ExternalDirName = xndd.InnerText; break; case "filename": rom.ExternalFileName = xndd.InnerText; break; } } DataBase.Add(rom); }
/// <summary> /// DataBinding of the selected Rom /// </summary> /// <param name="sender">DataGridView</param> /// <param name="e">EventArgs</param> private void Grid_CurrentCellChanged(object sender, EventArgs e) { DataGridView dgv = (DataGridView)sender; if (dgv.SelectedRows.Count == 1) { if (dgv["ReleaseNumber", dgv.SelectedRows[0].Index].Value != null) { _controler.SetCurrentNdsRom(dgv["ReleaseNumber", dgv.SelectedRows[0].Index].Value.ToString()); } NDS_Rom currentRom = _controler.GetCurrentRom(); lblLanguage.Text = currentRom.LanguageString; lblCRC.Text = currentRom.RomCRC; lblGenre.Text = currentRom.Genre; lblPublisher.Text = currentRom.Publisher; lblSaveType.Text = currentRom.SaveType; lblSize.Text = currentRom.RomSize; lblSource.Text = currentRom.SourceRom; lblSerial.Text = currentRom.Serial; lblInternalName.Text = currentRom.InternalName; lblVersion.Text = currentRom.Version; lblReleaseNumber.Text = currentRom.ReleaseNumber; lblDumpDate.Text = currentRom.DumpDate.ToShortDateString(); txtDirName.Text = currentRom.ExternalDirName; txtFileName.Text = currentRom.ExternalFileName; ImgCover.ImageLocation = currentRom.ImgCoverPath; ImgInGame.ImageLocation = currentRom.ImgInGamePath; ImgLocation.ImageLocation = currentRom.FlagPath; ImgIcon.ImageLocation = currentRom.ImgIconPath; if (currentRom.IsWifi()) { ImgWifi.Image = Properties.Resources.wifi; } else { ImgWifi.Image = Properties.Resources.wifi_no; } richTextBox1.LoadFile(new StreamReader(currentRom.NfoPath, Encoding.GetEncoding(437)).BaseStream, RichTextBoxStreamType.PlainText); if (File.Exists(_controler.GetCurrentRom().RomPath)) { btnUnzip.Enabled = true; btnUnzip.Text = Parameter.Lang.GetTranslate("btnUnzip_Enabled"); } else { btnUnzip.Enabled = false; btnUnzip.Text = Parameter.Lang.GetTranslate("btnUnzip_Disabled"); } if (_controler.GetCurrentRom().IsAllImagePresent()) { btnDownloadImgNfoOneRom.Enabled = false; btnDownloadImgNfoOneRom.Text = Parameter.Lang.GetTranslate("btnDownloadImgNfoOneRom_Disabled"); } else { btnDownloadImgNfoOneRom.Enabled = true; btnDownloadImgNfoOneRom.Text = Parameter.Lang.GetTranslate("btnDownloadImgNfoOneRom_Enabled"); } if (_controler.GetCurrentRom().IsDuplicate()) { btnFilterDuplicate.Enabled = true; btnFilterDuplicate.Text = Parameter.Lang.GetTranslate(_controler.IsDuplicateFilterActive() ? "btnFilterDuplicate_Reset" : "btnFilterDuplicate_Apply"); } else { btnFilterDuplicate.Enabled = false; btnFilterDuplicate.Text = Parameter.Lang.GetTranslate("btnFilterDuplicate_None"); } _controler.SetCurrentGridView(dgv.Name); } else { _controler.SetNoCurrentRom(); lblLanguage.Text = string.Empty; lblCRC.Text = string.Empty; lblGenre.Text = string.Empty; lblPublisher.Text = string.Empty; lblSaveType.Text = string.Empty; lblSize.Text = string.Empty; lblSource.Text = string.Empty; lblSerial.Text = string.Empty; lblInternalName.Text = string.Empty; lblVersion.Text = string.Empty; lblReleaseNumber.Text = string.Empty; lblDumpDate.Text = string.Empty; txtDirName.Text = string.Empty; txtFileName.Text = string.Empty; ImgCover.ImageLocation = string.Empty; ImgInGame.ImageLocation = string.Empty; ImgLocation.ImageLocation = string.Empty; ImgIcon.ImageLocation = string.Empty; ImgWifi.ImageLocation = string.Empty; richTextBox1.Clear(); btnUnzip.Enabled = false; btnUnzip.Text = Parameter.Lang.GetTranslate("btnUnzip_NoRom"); btnDownloadImgNfoOneRom.Enabled = false; btnDownloadImgNfoOneRom.Text = Parameter.Lang.GetTranslate("btnDownloadImgNfoOneRom_NoRom"); btnFilterDuplicate.Enabled = false; btnFilterDuplicate.Text = Parameter.Lang.GetTranslate("btnFilterDuplicate_NoRom"); } }
/// <summary> /// Get NDS_Rom from its release number /// </summary> /// <param name="releaseNumber">release number of a rom</param> /// <returns>NDS_Rom</returns> public NDS_Rom GetRomByReleaseNumber(string releaseNumber) { NDS_Rom rom = DataAcessLayer.NdsAdvanScene.Single(r => r.ReleaseNumber == releaseNumber); return(rom); }
/// <summary> /// No current Rom Selected /// </summary> public void SetNoCurrentRom() { _currentNDSRom = null; }
/// <summary> /// Set current selected rom from a release number /// </summary> /// <param name="romReleaseNumber">Rom Release number</param> public void SetCurrentNdsRom(string romReleaseNumber) { _currentNDSRom = GetRomByReleaseNumber(romReleaseNumber); }
/// <summary> /// set informations about the rom /// </summary> /// <param name="rom">NDS Rom</param> public void SetRomInfo(NDS_Rom rom) { RomInfo = rom; }
/// <summary> /// Add (or not) the file in the collection /// </summary> /// <param name="file">File path</param> /// <param name="crc">crc of the file</param> private void NdsFileIntegration(string file, string crc) { // string crc = GetCRC32FromFile(file); NDS_Rom romInfo = DataAcessLayer.FindCRCDataBase(crc.ToUpper()); if (romInfo != null) { if (DataAcessLayer.IsCRCInCollection(crc.ToUpper())) { RomInCollection(romInfo, file); } else { TypeAvancement infoAvancement = TypeAvancement.RomIntegrated; string complementNomXXXX = (romInfo.RomNumber == "xxxx") ? string.Format("({0})", romInfo.Serial) : string.Empty; if (DataAcessLayer.IsRomNumberInCollection(romInfo.RomNumber)) { NDS_Rom romBadDump = DataAcessLayer.GetCollectionRom(romInfo.RomNumber); /* * string fileArchive = string.Format( * "{0}{1}\\({2}) {3}{4}.7z", * NDSDirectories.PathRom, * NDSDirectories.GetDirFromReleaseNumber(romBadDump.RomNumber), * romBadDump.RomNumber, * romBadDump.title, * complementNomXXXX); */ string badDump = string.Format("{0}{1}", Parameter.Config.Paths.DirTrash, Path.GetFileName(romBadDump.RomPath)); if (File.Exists(badDump)) { File.Delete(badDump); } if (File.Exists(romBadDump.RomPath)) { File.Move(romBadDump.RomPath, badDump); } DataAcessLayer.NdsCollection.Remove(romBadDump); infoAvancement = TypeAvancement.RomIntegratedBadDump; } tos.SetIntituleTraitement(string.Format("CRC : {0} => {1} => Compressing ...", crc.ToUpper(), romInfo.Title)); ReportProgress(tos.Avance(infoAvancement), tos); Directory.CreateDirectory(Parameter.Config.Paths.DirTemp + crc.ToUpper()); string source = string.Format("{0}{1}\\{2}{3}.nds", Parameter.Config.Paths.DirTemp, crc.ToUpper(), romInfo.Title, complementNomXXXX); File.Move(file, source); string zipFile = string.Format("{0}({1}) {2}{3}.7z", Parameter.Config.Paths.DirTemp, romInfo.RomNumber, romInfo.Title, complementNomXXXX); try { ZipRom(zipFile, source); tos.SetIntituleTraitement(string.Format("Compressing {0} done", romInfo.Title)); File.Delete(source); Directory.Delete(Path.GetDirectoryName(source)); tos.SetRomInfo(romInfo); tos.SetRomInfoIntegration(infoAvancement, Path.GetFileName(file)); ReportProgress(tos.PourcentageAvancement(), tos); Directories.ArchiveRom(zipFile, romInfo.RomNumber); DataAcessLayer.NdsCollection.Add(romInfo); DataAcessLayer.SaveCollectionXML(); } catch (Exception ex) { // throw; tos.SetIntituleTraitement(string.Format("Une erreur est survenue pendant la compression:{0}{1}", Environment.NewLine, ex.Message)); File.Move(source, file); tos.SetRomInfo(romInfo); tos.SetRomInfoIntegration(TypeAvancement.Nothing, Path.GetFileName(file)); ReportProgress(tos.PourcentageAvancement(), tos); } } } else { RomNotFound(file, crc); } tos.SetRomInfo(null); tos.SetRomInfoIntegration(TypeAvancement.Nothing, null); }
/// <summary> /// Work of the worker /// </summary> /// <param name="sender">sender</param> /// <param name="e">DoWorkEventArgs</param> private void BW_VerifyCRCFiles_DoWork(object sender, DoWorkEventArgs e) { List <NDS_Rom> newCollection = new List <NDS_Rom>(); List <string> files = Directory.GetFiles(Parameter.Config.Paths.DirNdsRom, "*.7z", SearchOption.AllDirectories).ToList <string>(); files.Sort(); SevenZipExtractor.SetLibraryPath("7z.dll"); int nbFiles = files.Count; int numEnCours = 1; ReportProgress(-1); foreach (string file in files) { string romNumber = Path.GetFileNameWithoutExtension(file).Substring(1, 4); if (romNumber != "xxxx") { // DAL.XMLExplorateur xml = new DAL.XMLExplorateur(NDSDirectories.PathXmlDB); // NDS_Rom rom = new NDS_Rom(xml.SearchByRomNumberToXmlReader(RomNumber)); NDS_Rom rom = new NDS_Rom(); try { rom = DataAcessLayer.NdsAdvanScene.Single(r => r.RomNumber == romNumber); SevenZipExtractor szip = new SevenZipExtractor(file); foreach (ArchiveFileInfo adata in szip.ArchiveFileData) { if (adata.FileName == string.Format("{0}.nds", rom.Title)) { string sevenZipCRC = adata.Crc.ToString("X"); while (sevenZipCRC.Length != 8) { sevenZipCRC = string.Format("0{0}", sevenZipCRC); } if (sevenZipCRC == rom.RomCRC) { ReportProgress(numEnCours * 100 / nbFiles); newCollection.Add(rom); numEnCours++; } else { // NOT GOOD string log = string.Format( "{1} {0} 7z : {2}{0}Advanscene : {3}", " || ", Path.GetFileNameWithoutExtension(file), sevenZipCRC, rom.RomCRC); ReportProgress(numEnCours * 100 / nbFiles, log); File.AppendAllText(string.Format("{0}\\ReCreateCollection.log", _startuppath), string.Format("{0}{1}", log, Environment.NewLine)); // ReportProgress(NumEnCours * 100 / NbFiles, Path.GetFileNameWithoutExtension(file)); rom.RomCRC = sevenZipCRC; newCollection.Add(rom); numEnCours++; } } } } catch (Exception) { string message = string.Format( "{1}{0}7z : {2}{0}Advanscene : not Found", " || ", Path.GetFileNameWithoutExtension(file), romNumber); ReportProgress( numEnCours * 100 / nbFiles, message); } } else { ReportProgress(numEnCours * 100 / nbFiles); numEnCours++; } } XmlSerializer xs = new XmlSerializer(typeof(List <NDS_Rom>)); string path = Parameter.Config.Paths.XmlCollection.Replace("Collection.xml", "NewCollection.xml"); using (StreamWriter wr = new StreamWriter(path)) { xs.Serialize(wr, newCollection); } }