コード例 #1
0
        /// <summary>
        /// Avance
        /// </summary>
        /// <param name="ta">Type of work</param>
        /// <returns>Pourcentage d'avancement</returns>
        public int Avance(TypeAvancement ta)
        {
            switch (ta)
            {
            case TypeAvancement.RomNotFound:
                NbRomNotFound++;
                break;

            case TypeAvancement.RomAlreadyHave:
                NbRomAlreadyHave++;
                break;

            case TypeAvancement.RomIntegrated:
                NbRomIntegrated++;
                break;

            default:
                break;
            }

            NbActuel = NbRomNotFound + NbRomIntegrated + NbRomAlreadyHave;
            return(PourcentageAvancement());
        }
コード例 #2
0
 /// <summary>
 /// set actual informations of the worker job
 /// </summary>
 /// <param name="ta">What happen during integration</param>
 /// <param name="fn">File name</param>
 public void SetRomInfoIntegration(TypeAvancement ta, string fn)
 {
     WhatHappen = ta;
     FileName   = fn;
 }
コード例 #3
0
        /// <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);
        }