Beispiel #1
0
        public static void TestCreate()
        {
            // create a streaming archive file from existing files:
            StreamingArchiveFile arc = new StreamingArchiveFile(@"C:\Temp\streamingArchive.arc");

            // now iterate through the files in a specific directory and add them to the archive:
            foreach (string fileName in Directory.GetFiles(@"C:\Temp\Test\", "*.*"))
            {
                // add the file
                arc.AddFile(new ArchiveFile(fileName));
            }
        }
Beispiel #2
0
        /// <summary>
        /// remove a list of files from the archive by the archive file index.
        /// this works by duplicating the archive file into a temp location, skipping the files due to be deleted
        /// and then copying the duplicate back over the original.
        /// not the most inspired solution but better than nothing.
        /// </summary>
        /// <param name="filesToRemove"></param>
        public void RemoveFiles(List <ArchiveFileIndex> filesToRemove)
        {
            // create a temporary file:
            String tempFileName = Path.GetTempFileName();

            // create a temporary archive:
            StreamingArchiveFile tempArc = new StreamingArchiveFile(tempFileName);

            // extract each file from this archive, add it to the other archive,
            // except the files to be deleted.
            using (Stream input = GetStream())
            {
                using (Stream output = tempArc.GetStream())
                {
                    // enumerate the indexes:
                    foreach (ArchiveFileIndex idx in _index.ArchiveIndex)
                    {
                        if (!filesToRemove.Contains(idx))
                        {
                            // process this... read in the raw data block:
                            input.Seek(idx.FileStartIndex, SeekOrigin.Begin);

                            // read the compressed file data:
                            byte[] data = IndexHandler.ReadBuffer(input, idx.FileLength);

                            // now generate the raw index:
                            RawIndex rawIndex = new RawIndex()
                            {
                                N = idx.FileName,
                                L = idx.FileLength
                            };

                            // add to the destination:
                            AddRawData(output, rawIndex, data, tempArc._index);
                        }
                    }
                }
            }



            // now copy the temp file back over the archive:
            File.Delete(_fileName);
            File.Move(tempFileName, _fileName);

            // now re-read the indexes:
            OpenArchive(_fileName);
        }
Beispiel #3
0
        public static void TestOpen()
        {
            // open the existing archive file:
            StreamingArchiveFile arc = new StreamingArchiveFile(@"C:\Temp\streamingArchive.arc");

            // iterate the files in the archive:
            foreach (string fileName in arc.FileIndex.IndexedFileNames)
            {
                // write the name of the file
                Debug.Print("File: " + fileName);

                // extract the file:
                ArchiveFile file = arc.GetFile(fileName);

                // save it to disk:
                String tempFileName = Path.GetTempPath() + "\\" + file.Name;
                file.SaveAs(tempFileName);

                // open the file:
                Process.Start(tempFileName);
            }
        }
        public static void TestOpen()
        {
            // open the existing archive file:
            StreamingArchiveFile arc = new StreamingArchiveFile(@"C:\Temp\streamingArchive.arc");

            // iterate the files in the archive:
            foreach (string fileName in arc.FileIndex.IndexedFileNames)
            {
                // write the name of the file
                Debug.Print("File: " + fileName);

                // extract the file:
                ArchiveFile file = arc.GetFile(fileName);

                // save it to disk:
                String tempFileName = Path.GetTempPath() + "\\" + file.Name;
                file.SaveAs(tempFileName);

                // open the file:
                Process.Start(tempFileName);
            }
        }
        public static void TestCreate()
        {
            // create a streaming archive file from existing files:
            StreamingArchiveFile arc = new StreamingArchiveFile(@"C:\Temp\streamingArchive.arc");

            // now iterate through the files in a specific directory and add them to the archive:
            foreach (string fileName in Directory.GetFiles(@"C:\Temp\Test\", "*.*"))
            {
                // add the file
                arc.AddFile(new ArchiveFile(fileName));
            }

        }
        /// <summary>
        /// remove a list of files from the archive by the archive file index.
        /// this works by duplicating the archive file into a temp location, skipping the files due to be deleted
        /// and then copying the duplicate back over the original.
        /// not the most inspired solution but better than nothing.
        /// </summary>
        /// <param name="filesToRemove"></param>
        public void RemoveFiles(List<ArchiveFileIndex> filesToRemove)
        {
            // create a temporary file:
            String tempFileName = Path.GetTempFileName();

            // create a temporary archive:
            StreamingArchiveFile tempArc = new StreamingArchiveFile(tempFileName);

            // extract each file from this archive, add it to the other archive,
            // except the files to be deleted.
            using (Stream input = GetStream())
            {
                using (Stream output = tempArc.GetStream())
                {
                    // enumerate the indexes:
                    foreach (ArchiveFileIndex idx in _index.ArchiveIndex)
                    {
                        if (!filesToRemove.Contains(idx))
                        {
                            // process this... read in the raw data block:
                            input.Seek(idx.FileStartIndex, SeekOrigin.Begin);

                            // read the compressed file data:
                            byte[] data = IndexHandler.ReadBuffer(input, idx.FileLength);

                            // now generate the raw index:
                            RawIndex rawIndex = new RawIndex()
                            {
                                N = idx.FileName,
                                L = idx.FileLength
                            };

                            // add to the destination:
                            AddRawData(output, rawIndex, data, tempArc._index);
                        }
                    }
                }
            }

            

            // now copy the temp file back over the archive:
            File.Delete(_fileName);
            File.Move(tempFileName, _fileName);

            // now re-read the indexes:
            OpenArchive(_fileName);

        }
Beispiel #7
0
        public static void ExportTo(string filePath)
        {
            //如果已经存在,则先删掉。否则Archive会添加文件进去
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var arcFile = new StreamingArchiveFile(filePath);
            arcFile.AddFile(new ArchiveFile(AppSettings.ConfigFilePath));
            arcFile.AddFile(new ArchiveFile(AppSettings.GesturesFilePath));

        }
Beispiel #8
0
        public static ConfigAndGestures ImportWgb(string wgbFilePath)
        {
            if (!File.Exists(wgbFilePath))
            {
                throw new MigrateException("文件不存在:" + wgbFilePath);
            }

            var config = null as PlistConfig;
            var gestures = null as JsonGestureIntentStore;

            var cofnigFileName = Path.GetFileName(AppSettings.ConfigFilePath);
            var gesturesFileName = Path.GetFileName(AppSettings.GesturesFilePath);

            var arcFile = new StreamingArchiveFile(wgbFilePath);
            var files = arcFile.FileIndex.IndexedFileNames.ToArray();

            /*var fileShortNames = (from f in files select Path.GetFileName(f)).ToArray();
            if (!fileShortNames.Contains(cofnigFileName) || !fileShortNames.Contains(gesturesFileName))
                throw new MigrateException("文件内容不正确(未找到需要的部分): " + wgbFilePath);*/

            try
            {
                // iterate the files in the archive:
                foreach (var fileName in files)
                {
                    // write the name of the file
                    Debug.Print("File: " + fileName);

                    // extract the file:
                    var file = arcFile.GetFile(fileName);
                    //file.SaveAs("text.txt");

                    //config file
                    if (Path.GetFileName(fileName) == cofnigFileName)
                    {
                        config = new PlistConfig(file.GetStream(), closeStream: true);

                    }
                    else
                    {
                        var version = "1";
                        if (fileName.EndsWith(".json"))
                        {
                            version = "1";
                        }
                        else if (fileName.EndsWith(".wg"))
                        {
                            version = "2";
                        }
                        gestures = new JsonGestureIntentStore(file.GetStream(), true, version);
                    }

                }
            }
            catch (Exception e)
            {
                if (e is SystemException) throw;
                throw new MigrateException("文件内容错误");
            }
            

            if(config == null || gestures == null) throw new MigrateException("文件内容错误");

            return new ConfigAndGestures(config, gestures);
            

        }