コード例 #1
0
        private void zipButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (SelectedItemList != null)
                {
                    string startPath = Path.Combine(ListFiles.varListPath, SelectedItemList.Name);
                    if (Directory.Exists(Path.Combine(ListFiles.varListPath, SelectedItemList.Name)) && Directory.GetParent(SelectedItemList.Name) != null)
                    {
                        string zipPath = Path.Combine(ListFiles.varListPath, Translit.TranslitFileName(SelectedItemList.Name) + @".zip");

                        Thread th = new Thread(delegate() { ZipFile.CreateFromDirectory(startPath, zipPath); });
                        LoadScreenStart();
                        th.Start();

                        Thread stoped = new Thread(delegate() { checkThread(th); });
                        stoped.Start();
                    }
                    else if (File.Exists(Path.Combine(ListFiles.varListPath, SelectedItemList.Name)))
                    {
                        string zipPath = Path.Combine(ListFiles.varListPath, Translit.TranslitFileName(Path.GetFileNameWithoutExtension(SelectedItemList.Name)));
                        Thread th      = new Thread(delegate()
                        {
                            Directory.CreateDirectory(zipPath);
                            File.Copy(Path.Combine(ListFiles.varListPath, SelectedItemList.Name), Path.Combine(zipPath, SelectedItemList.Name));
                            ZipFile.CreateFromDirectory(zipPath, zipPath + ".zip");
                            Directory.Delete(zipPath, true);
                        });
                        LoadScreenStart();
                        th.Start();

                        Thread stoped = new Thread(delegate() { checkThread(th); });
                        stoped.Start();


                        //ListFiles.OutDirAndFiles(RightListFile, ListFiles.varListPath);
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
コード例 #2
0
        public static string EncryptFile(string sInputFilename, string sOutputDir, string sKey, bool isDir)
        {
            string     sOutputFilename = Path.Combine(sOutputDir, Translit.TranslitFileName(Path.GetFileNameWithoutExtension(sInputFilename)) + ".des");
            FileStream fsInput         = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read);
            FileStream fsEncrypted     = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write);

            DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

            DES.Key = Get8BytesHashCode(sKey);
            DES.IV  = Get8BytesHashCode(sKey);
            ICryptoTransform desencrypt = DES.CreateEncryptor();

            CryptoStream cryptostream = new CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write);

            string CryptFileName = Translit.TranslitFileName(Path.GetFileName(sInputFilename));

            if (isDir)
            {
                CryptFileName = "/" + CryptFileName;
            }
            byte[]       byteArray = Encoding.ASCII.GetBytes(CryptFileName + "\n");
            MemoryStream stream    = new MemoryStream(byteArray);

            byte[] bytearrayinputFileName = new byte[stream.Length];
            stream.Read(bytearrayinputFileName, 0, bytearrayinputFileName.Length);
            fsEncrypted.Write(bytearrayinputFileName, 0, bytearrayinputFileName.Length);

            byte[] bytearrayinput = new byte[fsInput.Length];
            fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
            cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

            cryptostream.Close();
            fsEncrypted.Close();
            fsInput.Close();

            return(sOutputFilename);
        }