Пример #1
0
        static void Main(string[] args)
        {
            string sourceFile     = "u12.jpg";  // исходный файл
            string compressedFile = "test2.gz"; // сжатый файл
            string newFile        = "u13.jpg";


            Ziper.Compress(sourceFile, compressedFile);
            Ziper.Decompress(compressedFile, newFile);
            // Compress(sourceFile,compressedFile);
        }
Пример #2
0
        public void ZiperTest()
        {
            string str = null;

            AssertThat.DoesNotThrowException(() => { str = Ziper.TempPath; });
            AssertThat.IsTrue(Directory.Exists(str));
            Directory.CreateDirectory("Test");
            File.WriteAllText(@"Test\Test", "Test");
            AssertThat.DoesNotThrowException(() => { Ziper.Zip("Test.zip", "Test"); });
            AssertThat.DoesNotThrowException(() => { Ziper.UnZip("Test.zip", "Test-copy"); });
            AssertThat.AreEqual(File.ReadAllText(@"Test-copy\Test"), IS.a("Test"));
            File.Delete("Test.zip");
            Directory.Delete("Test", true);
            Directory.Delete("Test-copy", true);
        }
Пример #3
0
        public static void Start(
            string Path,
            Form form,
            SetMax Max,
            SetValue Value,
            SetLabel Label,
            Action End,
            Action Error,
            bool HideMessages,
            bool DeleteMessages,
            bool HideNicknames,
            bool HideServerIDs,
            bool HideServerNames,
            bool HideChannelIDs,
            bool HideChannelNames,
            bool HideApplication,
            bool DeleteApplication,
            bool HideOS,
            bool HideIPs,
            bool HideLocations,
            bool DeleteActivities
            )
        {
            Task t = new Task(() =>
            {
                form.Invoke(Max, 114);
                form.Invoke(Value, 0);
                int start = 0;
                int max   = 0;

                #region UnZip
                max = 5;
                form.Invoke(Label, "UnZip");
                if (!Ziper.UnZip(Path))
                {
                    form.Invoke(Error, "UnZipFailed");
                    return;
                }
                form.Invoke(Value, start += max);
                #endregion

                #region IDs
                max = 2;
                form.Invoke(Label, "IDs");
                try
                {
                    ServerIDs      = new Dictionary <string, string>();
                    ChannelIDs     = new Dictionary <string, string>();
                    string channel = $@"{Ziper.TempPath}\messages\index.json";
                    string servers = $@"{Ziper.TempPath}\servers\index.json";

                    JServerIDs  = File.Exists(servers) ? JObject.Parse(File.ReadAllText(servers)) : null;
                    JChannelIDs = File.Exists(channel) ? JObject.Parse(File.ReadAllText(channel)) : null;
                }
                catch { form.Invoke(Error, "IDsFailed"); return; }
                form.Invoke(Value, start += max);
                #endregion

                #region Messages Channel
                max = 35;
                form.Invoke(Label, "Messages");
                string messages = $@"{Ziper.TempPath}\messages";
                try
                {
                    if (Directory.Exists(messages))
                    {
                        string[] directories = Directory.GetDirectories(messages);
                        if (DeleteMessages)
                        {
                            foreach (string directory in Directory.GetDirectories(messages))
                            {
                                Directory.Delete(directory, true);
                            }
                        }
                        else if (HideMessages)
                        {
Пример #4
0
        /// <summary>
        /// 根据key搜索当前目录下匹配的文件
        /// </summary>
        /// <param name="dir">当前文件夹</param>
        /// <param name="key">搜索关键字</param>
        public void SearchInSelectedDir(string dir, string key)
        {
            var swTotal = Stopwatch.StartNew();

            stopwatch.Start();
            FilesListView.Items.Clear();

            string combinedKey = GetCombinedKey(key);

            if (RedisHelper.Exists(combinedKey))
            {
                MessageBox.Show("从缓存获取成功");
                matchedFilenameList = RedisHelper.ListGet <string>(combinedKey);
                foreach (var matchedPath in matchedFilenameList)
                {
                    // 判断文件更新
                    string oriMD5 = RedisHelper.Get <string>(GetMD5Key(matchedPath));
                    string curMD5 = MD5Checker.GetFileMD5(matchedPath);
                    if (oriMD5 != curMD5)
                    {
                        // 摘要发生变化
                        // todo 移除缓存
                        RenewFile(matchedPath, key);
                    }
                }
                DispMatchedFiles();
            }
            else
            {
                //提前解压缩
                var sw    = Stopwatch.StartNew();
                var ziper = new Ziper();
                TR.ZipSearched.AddRange(ziper.extract(dir));
                sw.Stop();
                TR.Zip = sw.Elapsed.TotalMilliseconds * 1e6;

                TR.Doc = 0;
                TR.Img = 0;
                var files = Directory.GetFiles(curDirPath, "*.*", SearchOption.AllDirectories);
                foreach (var filename in files)
                {
                    if (IsImageFile(filename))
                    {
                        TR.ImgSearched.Add(filename);
                        Console.WriteLine(filename);
                        sw = Stopwatch.StartNew();
                        ImageContainsKey(filename, key);
                        sw.Stop();
                        TR.Img += sw.Elapsed.TotalMilliseconds * 1e6;
                    }
                    else if (IsDocFile(filename))
                    {
                        TR.DocSearched.Add(filename);
                        Console.WriteLine(filename);
                        sw = Stopwatch.StartNew();
                        DocumentContainsKey(filename, key, ziper.Table);
                        sw.Stop();
                        TR.Doc += sw.Elapsed.TotalMilliseconds * 1e6;
                    }
                }
                //清除被解压的文件夹
                ziper.ClearFile();
            }

            stopwatch.Stop();
            DispElapsedTime();

            swTotal.Stop();
            TR.Total = swTotal.Elapsed.TotalMilliseconds * 1e6;
        }