Exemplo n.º 1
0
        public void FormatSize()
        {
            var lzssFileInfo = new Data.LZSSFileItem();

            lzssFileInfo.Size = 999;
            var fileData = new Data.FileData(lzssFileInfo);

            Assert.AreEqual("999 B", fileData.FormattedSize);

            lzssFileInfo.Size = 1023;
            fileData          = new Data.FileData(lzssFileInfo);
            Assert.AreEqual("1 K", fileData.FormattedSize);

            lzssFileInfo.Size = 1025;
            fileData          = new Data.FileData(lzssFileInfo);
            Assert.AreEqual("1 K", fileData.FormattedSize);

            lzssFileInfo.Size = 541696;
            fileData          = new Data.FileData(lzssFileInfo);
            Assert.AreEqual("529 K", fileData.FormattedSize);

            lzssFileInfo.Size = 1099511627776;
            fileData          = new Data.FileData(lzssFileInfo);
            Assert.AreEqual("1 T", fileData.FormattedSize);
        }
Exemplo n.º 2
0
        private static void moveToTargetFolder(Data.FileData file)
        {
            try
            {
                FileInfo unpackedFile = new FileInfo(Path.Combine(ConfigManager.OFDRRootFolder, file.OutputName));
                if (!unpackedFile.Exists)
                {
                    Console.WriteLine("cannot unpack file: \"{0}\"", file.Name);
                    file.TreeNode.State = Data.TreeNodeState.Error;
                    return;
                }
                Console.WriteLine("file unpacked: \"{0}\"", file.Name);

                FileInfo targetFile = new FileInfo(Path.Combine(ConfigManager.OutputFolder, file.OutputFullName));
                if (!targetFile.Directory.Exists)
                {
                    targetFile.Directory.Create();
                }
                unpackedFile.MoveTo(targetFile.FullName);
                Console.WriteLine("file moved to: \"{0}\"", targetFile.FullName);

                file.TreeNode.State = Data.TreeNodeState.Ready;
            }
            catch
            {
                file.TreeNode.State = Data.TreeNodeState.Error;
                throw;
            }
        }
Exemplo n.º 3
0
 private static void raiseCompleted(Data.FileData file)
 {
     if (Completed != null)
     {
         Completed(file, EventArgs.Empty);
     }
 }
Exemplo n.º 4
0
 private static void raiseExtracted(Data.FileData fileData)
 {
     if (Extracted != null)
     {
         Extracted(fileData, EventArgs.Empty);
     }
 }
Exemplo n.º 5
0
        private static Data.FolderData convert(Task <IList <Data.LZSSFileItem> > parseIndexTask)
        {
            var checker = Business.CodeTimeChecker.New;

            Business.StatusManager.Instance.UpdateProgress(0.9);
            Business.StatusManager.Instance.UpdateStatus("converting...");
            try
            {
                if (parseIndexTask.Exception != null)
                {
                    throw parseIndexTask.Exception;
                }

                if (parseIndexTask.IsCanceled)
                {
                    return(null);
                }

                var lzssFiles = parseIndexTask.Result;
                if (lzssFiles == null || lzssFiles.Count == 0)
                {
                    return(null);
                }

                Regex folderFilter = new Regex(folderFilterToken);

                var rootFolder    = new Data.FolderData(rootFolderName);
                var currentFolder = rootFolder;
                foreach (var lzssItem in lzssFiles)
                {
                    if (folderFilter.IsMatch(lzssItem.Name))                     //folder
                    {
                        if (lzssItem.Name == currentFolder.Name)
                        {
                            continue;
                        }

                        var folder = new Data.FolderData(lzssItem.Name);
                        rootFolder.Add(folder);
                        currentFolder = folder;
                    }
                    else                     //file
                    {
                        var file = new Data.FileData(lzssItem);
                        currentFolder.Add(file);
                    }
                }

                return(rootFolder);
            }
            catch
            {
                throw;
            }
            finally
            {
                checker.Check("LZSSFileMapParser.convert");
            }
        }
Exemplo n.º 6
0
            public Extractor(Data.FileData fileData)
            {
                if (fileData == null)
                {
                    throw new ArgumentNullException("fileData");
                }

                this.fileData = fileData;
            }
Exemplo n.º 7
0
        public static void Extract(this Data.FileData fileData)
        {
            if (fileData == null)
            {
                throw new ArgumentNullException("fileData");
            }

            Extractor extractor = new Extractor(fileData);

            extractor.Extracted += onExtracted;
            extractor.Extract();
        }
Exemplo n.º 8
0
 private static Data.IOFile toOuter(Data.FileData inner)
 {
     if (inner == null)
     {
         return(null);
     }
     return(new Data.IOFile()
     {
         Name = inner.Name,
         Size = inner.Size,
         Index = inner.Index
     });
 }
Exemplo n.º 9
0
        public void OutputName()
        {
            var lzssFileInfo = new Data.LZSSFileItem()
            {
                Name = "test file.txt",
                Size = 1
            };

            lzssFileInfo.Index = 0;
            var fileData = new Data.FileData(lzssFileInfo);

            Assert.AreEqual("test file.txt", fileData.OutputName);

            lzssFileInfo.Index = 1;
            fileData           = new Data.FileData(lzssFileInfo);
            Assert.AreEqual("test file.txt1", fileData.OutputName);
        }