Пример #1
0
        private Boolean ProcessRezFile(BackgroundWorker bgw)
        {
            string rezFilePath = Path.Combine(_offlineListCacheLocation, Utils.Utils.GetRezFileName(_fileType));

            if (File.Exists(rezFilePath))
            {
                foreach (string item in File.ReadLines(rezFilePath).AsParallel())
                {
                    if (bgw.CancellationPending)
                    {
                        return(false);
                    }

                    string[] subitems = item.Split(";".ToArray());

                    DatCacheEntity datCacheEntity = _datCacheEntities.FirstOrDefault(x => x.FilePath == subitems[0]);
                    if (datCacheEntity != null)
                    {
                        if (datCacheEntity.FilePath == subitems[0] &&
                            datCacheEntity.ModifyNo == Convert.ToUInt32(subitems[1]) &&
                            datCacheEntity.CompressedFileSize == unchecked ((Int32)Convert.ToInt64(subitems[2])) &&
                            !datCacheEntity.IsAltered)
                        {
                            datCacheEntity.IsArchived = true;
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        private Boolean ProcessDirectory(BackgroundWorker bgw)
        {
            int    progress             = 0;
            string userFriendlyProgress = string.Empty;
            string filePath             = string.Empty;
            string fileType             = Utils.Utils.GetFileTypeValue(_fileType);

            string[] files = Directory.GetFiles(Path.Combine(_romLocation, fileType));

            for (int i = 0; i < files.Length; i++)
            {
                if (bgw.CancellationPending)
                {
                    return(false);
                }

                progress             = (int)((float)i / (float)files.Length * 100);
                userFriendlyProgress = string.Format("{0}/{1}", i, files.Length);
                bgw.ReportProgress(progress, userFriendlyProgress);

                filePath = files[i];

                DatCacheEntity datCacheEntity = new DatCacheEntity();
                LoadSingleCache(filePath, datCacheEntity);

                _datCacheEntities.Add(datCacheEntity);
            }
            return(true);
        }
Пример #3
0
 private void RearchiveCompleted(DatCacheEntity datCacheEntity)
 {
     // Make sure someone is listening to event
     if (OnRearchiveCompleted != null)
     {
         OnRearchiveCompleted(datCacheEntity);
     }
 }
Пример #4
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int progress   = 0;
            int totalCount = _datCacheEntities.Count();

            BackgroundWorker bgw = (BackgroundWorker)sender;

            for (int i = 0; i < totalCount; i++)
            {
                DatCacheEntity datCacheEntity = _datCacheEntities.ElementAt(i);
                RearchiveStarted(datCacheEntity);

                progress = (int)((float)i / (float)totalCount * 100);
                OverallProgressChanged(progress, string.Format("{0}/{1}", i, totalCount));

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                _sevenZipProcessor = new SevenZipProcessor();
                _sevenZipProcessor.OnExceptionOccured += _sevenZipProcessor_OnExceptionOccured;
                _sevenZipProcessor.OnProgressChanged  += _sevenZipProcessor_OnProgressChanged;
                _sevenZipProcessor.OnCompleted        += _sevenZipProcessor_OnCompleted;

                IProcessInfo decomprocessInfo = new DecompressInfo(datCacheEntity.FilePath, ConfigReader.Instance.WorkingDirectory);
                _sevenZipProcessor.Run(decomprocessInfo);

                string extractedFilePath = Path.Combine(ConfigReader.Instance.WorkingDirectory, datCacheEntity.FilenameInArchive);

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                _sevenZipProcessor = new SevenZipProcessor();
                _sevenZipProcessor.OnExceptionOccured += _sevenZipProcessor_OnExceptionOccured;
                _sevenZipProcessor.OnProgressChanged  += _sevenZipProcessor_OnProgressChanged;
                _sevenZipProcessor.OnCompleted        += _sevenZipProcessor_OnCompleted;

                IProcessInfo compressInfo = new CompressInfo(extractedFilePath, datCacheEntity.FilePath, ConfigReader.Instance.WorkingDirectory);
                _sevenZipProcessor.Run(compressInfo);

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                datCacheEntity.IsArchived = true;
                datCacheEntity.IsAltered  = false;

                RearchiveCompleted(datCacheEntity);
            }
            RearchiveOverallCompleted();
        }
Пример #5
0
        private void CheckFileHasAltered(bool isCancellationPending, string line)
        {
            if (isCancellationPending)
            {
                return;
            }

            string[] subitems = line.Split(";".ToArray());

            DatCacheEntity datCacheEntity = _datCacheEntities.FirstOrDefault(x => x.FilePath == subitems[0]);

            if (datCacheEntity != null)
            {
                datCacheEntity.IsAltered = ((datCacheEntity.FilenameInArchive != subitems[1] || datCacheEntity.ModifyNo != Convert.ToUInt32(subitems[2]) || datCacheEntity.CompressedFileSize != (unchecked ((Int32)Convert.ToInt64((subitems[3])))) || datCacheEntity.Crc != subitems[4]));
            }
        }
Пример #6
0
        private void LoadSingleCache(string filePath, DatCacheEntity datCacheEntity)
        {
            FileInfo fileInfo         = new FileInfo(filePath);
            string   archivedFilePath = GetArchivedFilePath(fileInfo.FullName, fileInfo.Extension);

            datCacheEntity.FilePath          = fileInfo.FullName;
            datCacheEntity.FilenameInArchive = archivedFilePath;
            datCacheEntity.ModifyNo          = Utils.Utils.CalculateModifyNumber(fileInfo.LastWriteTimeUtc);

            datCacheEntity.CompressedFileSize = unchecked ((Int32)(fileInfo.Length));
            datCacheEntity.ArchiveType        = fileInfo.Extension.Substring(1, fileInfo.Extension.Length - 1);
            datCacheEntity.Cleaned            = true;

            using (SevenZipExtractor sevenZipExtractor = new SevenZipExtractor(fileInfo.FullName))
            {
                datCacheEntity.Crc      = sevenZipExtractor.ArchiveFileData[0].Crc.ToString("X8");
                datCacheEntity.FileSize = sevenZipExtractor.ArchiveFileData[0].Size;
            }
        }
Пример #7
0
 internal void RefreshSingleEntity(DatCacheEntity datCacheEntity)
 {
     LoadSingleCache(datCacheEntity.FilePath, datCacheEntity);
 }