Пример #1
0
        public List <FileListData> GetAll()
        {
            XmlDocument doc        = new XmlDocument();
            string      fileName   = "../../Resourses/DownloadInfo.xml";
            string      XPATH      = "//files/file";
            var         collection = new List <FileListData>();

            doc.Load(fileName);
            XPathNavigator navigator = doc.CreateNavigator();

            //XPathNodeIterator bookNodesIterator = navigator.Select(XPATH);

            //if (bookNodesIterator.Current != null)
            //{
            //    var sdf = bookNodesIterator.Current.UnderlyingObject;
            //}

            foreach (XPathNavigator nav in navigator.Select(XPATH))
            {
                FileListData data = new FileListData();
                data.Title = nav.GetAttribute("title", string.Empty);
                data.Link  = nav.GetAttribute("link", string.Empty);
                collection.Add(data);
            }

            return(collection);
        }
Пример #2
0
        private void btnRedo_Click(object sender, System.EventArgs e)
        {
            if (verdata == null)
            {
                lblmsg.Text = "刷新版本信息出错!请重试!";
                return;
            }

            DirectoryInfo di = new DirectoryInfo(FolderPath);

            string tofile = Path.Combine(
                Path.Combine(di.Parent.FullName, ConfigurationValues.DownDir),
                ConfigurationValues.DataFileName);

            verdata.WriteXml(tofile, XmlWriteMode.WriteSchema);

            lblmsg.Text  = "写版本信息成功!\n";
            lblmsg.Text += "正在压缩...\n";
            Application.DoEvents();


            if (!di.Exists)
            {
                lblmsg.Text += "压缩失败!";
                return;
            }

            string zipedfile = Path.Combine(di.Parent.FullName + "\\" + ConfigurationValues.DownDir, di.Name + ".zip");
            bool   bret      = Tools.ZipLibrary.ZipHelper.ZipDirectory(FolderPath, zipedfile);

            if (!bret)
            {
                lblmsg.Text += "压缩失败.请重试.";
                return;
            }
            FileInfo fi = new FileInfo(zipedfile);

            if (fi.Exists)
            {
                lblmsg.Text += "压缩成功.压缩文件为:\n" + zipedfile;

                FileListData fld = new FileListData();
                DataRow      row = fld.Tables[FileListData.mTableName].NewRow();
                row[FileListData.mFileName]   = fi.Name;
                row[FileListData.mFileLength] = fi.Length;
                fld.Tables[FileListData.mTableName].Rows.Add(row);

                tofile = Path.Combine(
                    Path.Combine(di.Parent.FullName, ConfigurationValues.DownDir),
                    ConfigurationValues.ListFileName);

                fld.WriteXml(tofile, XmlWriteMode.WriteSchema);

                lblmsg.Text += "生成下载列表文件成功!\n";
            }
        }
Пример #3
0
        /// <summary>
        /// 获得文件列表 网络访问数据回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Request_FileList_HttpCompleted(object sender, WP7HttpEventArgs e)
        {
            FileListData data = FileListData.Create(e.Result, e.IsError);

            if (e.IsError)
            {
                MessageBox.Show(data.ErrorMessage);
            }
            else
            {
                string content = "文件总数为" + data.Count.ToString() + "\n";
                foreach (FileData fileData in data.DataList)
                {
                    content += fileData.FileName + "\n";
                }
                MessageBox.Show(content);
            }
        }
Пример #4
0
        private void btnRedo_Click(object sender, System.EventArgs e)
        {
            WizardObjects.MainCtler.SetButtonStates();


            richTextBox1.Text = "";
            richTextBox1.Clear();

            richTextBox1.Text = "";

            richTextBox1.Text = "正在下载配置文件...";
            Application.DoEvents();

            string dstdir = Application.StartupPath;
            string url1   = Path.Combine(ConfigurationValues.UpdateServerPath, ConfigurationValues.DataFileName);
            string url2   = Path.Combine(ConfigurationValues.UpdateServerPath, ConfigurationValues.ListFileName);

            string l1 = Path.Combine(dstdir, ConfigurationValues.DataFileName);
            string l2 = Path.Combine(dstdir, ConfigurationValues.ListFileName);

            if (File.Exists(l1))
            {
                File.Delete(l1);
            }
            if (File.Exists(l2))
            {
                File.Delete(l2);
            }

            bool bret = BatchDownload(new string[] { url1, url2 }, dstdir);

            if (!bret)
            {
                richTextBox1.Text += "\n下载配置文件失败,请检查网络是否正常、服务器路径设置是否正确。";
                richTextBox1.Text += "\n当前服务器路径:" + ConfigurationValues.UpdateServerPath;

                WizardObjects.MainCtler.SetButtonStates();
                return;
            }
            else
            {
                richTextBox1.Text += "\n下载配置文件成功.正在比较版本...";
            }
            Application.DoEvents();

            if (File.Exists(Path.Combine(dstdir, ConfigurationValues.DataFileName)))
            {
                GlobalObjects.ServerVerData.Clear();
                GlobalObjects.ServerVerData.ReadXml(Path.Combine(dstdir, ConfigurationValues.DataFileName), XmlReadMode.ReadSchema);
            }
            VersionData serVersion = GlobalObjects.ServerVerData;

            if (File.Exists(Path.Combine(dstdir, ConfigurationValues.ListFileName)))
            {
                GlobalObjects.ServerFileData.Clear();
                GlobalObjects.ServerFileData.ReadXml(Path.Combine(dstdir, ConfigurationValues.ListFileName), XmlReadMode.ReadSchema);
            }
            FileListData filelist = GlobalObjects.ServerFileData;

            if ((serVersion == null) || (filelist == null))
            {
                richTextBox1.Text += "\n读配置文件出错,请重试。";
                Application.DoEvents();

                WizardObjects.MainCtler.SetButtonStates();
                return;
            }

            string outputversion = "";

            foreach (DataRow row in serVersion.Tables[VersionData.mTableName].Rows)
            {
                string exename = row[VersionData.mExeName].ToString();

                DirectoryInfo curdi    = new DirectoryInfo(Application.StartupPath);
                DirectoryInfo parentdi = curdi.Parent;

                string exefullname    = Path.Combine(parentdi.FullName, exename);
                string dircopyto      = Path.Combine(curdi.FullName, GlobalObjects.C_Temp);
                string tmpexefullname = Path.Combine(dircopyto, exename + Guid.NewGuid().ToString());

                if (!Directory.Exists(dircopyto))
                {
                    Directory.CreateDirectory(dircopyto);
                }

                outputversion += "文件名:" + exename + "\n";
                outputversion += "服务器版本:" + row[VersionData.mFullVersion].ToString() + "\n";

                Application.DoEvents();

                try
                {
                    if (File.Exists(exefullname))
                    {
                        if (File.Exists(tmpexefullname))
                        {
                            File.Delete(tmpexefullname);
                        }

                        File.Copy(exefullname, tmpexefullname, true);

                        //Assembly assm = Assembly.LoadFrom(tmpexefullname);
                        //if (assm == null) continue;

                        //string cliver = assm.GetName().Version.ToString();
                        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(tmpexefullname);
                        string          cliver            = myFileVersionInfo.FileVersion;

                        //assm = null;

                        outputversion += "客户端版本:" + cliver + "\n";
                        outputversion += "\n";

                        this.hasnewver = false;
                        if (Helper.IsNewVersion(new Version(cliver),
                                                new Version(row[VersionData.mFullVersion].ToString())))
                        {
                            hasnewver = true;
                        }
                    }
                    else
                    {
                        outputversion += "客户端版本:无\n";
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("升级出错:" + ex.Message, "提示");
                }
            }

            if (hasnewver)
            {
                richTextBox1.Text += "\n\n程序发现新版本.";
            }
            else
            {
                richTextBox1.Text += "\n\n程序没有发现新版本.";
            }

            richTextBox1.Text += "\n\n" + outputversion;

            Application.DoEvents();


            if (hasnewver)
            {
                WizardObjects.MainCtler.SetButtonStates();
            }
            else
            {
                WizardObjects.MainCtler.SetButtonStates();
            }
        }
Пример #5
0
        /// <summary>
        /// The encrypted file by AES (exactly Rijndael) to the original file or folder by user's password.
        /// ユーザーが設定したパスワードによって、AES(正確にはRijndael)によって暗号化されたファイルを
        /// 元のファイル、またはフォルダーに復号して戻す。
        /// </summary>
        /// <param name="FilePath">File path or directory path is encrypted</param>
        /// <param name="OutFileDir">The directory of outputing encryption file.</param>
        /// <param name="Password">Encription password string</param>
        /// <returns>bool true: Success, false: Failed</returns>
        public bool Decrypt(
      object sender, DoWorkEventArgs e,
      string FilePath, string OutDirPath, string Password, byte[] PasswordBinary, Action<int, string> dialog)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
              worker.WorkerSupportsCancellation = true;

              //-----------------------------------
              // Header data is starting.
              // Progress event handler
              ArrayList MessageList = new ArrayList();
              MessageList.Add(READY_FOR_DECRYPT);
              MessageList.Add(Path.GetFileName(FilePath));
              worker.ReportProgress(0, MessageList);

              int len = 0;
              byte[] byteArray;

              List<string> FileList = new List<string>();
              Dictionary<int, FileListData> dic = new Dictionary<int, FileListData>();

              if (_TokenStr.Trim() == "_AttacheCaseData")
              {
            // Atc data
              }
              else if (_TokenStr.Trim() == "_Atc_Broken_Data")
              {
            // Atc file is broken
            e.Result = new FileDecryptReturnVal(ATC_BROKEN_DATA, FilePath);
            return (false);
              }
              else
              {
            // not AttacheCase data
            e.Result = new FileDecryptReturnVal(NOT_ATC_DATA, FilePath);
            return(false);
              }

              Rfc2898DeriveBytes deriveBytes;
              if (PasswordBinary == null)
              {
            deriveBytes = new Rfc2898DeriveBytes(Password, _salt, 1000);
              }
              else
              {
            deriveBytes = new Rfc2898DeriveBytes(PasswordBinary, _salt, 1000);
              }

              byte[] key = deriveBytes.GetBytes(32);
              byte[] iv = deriveBytes.GetBytes(32);

              using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
              {
            if (fs.Length < 32)
            {
              // not AttacheCase data
              e.Result = new FileDecryptReturnVal(NOT_ATC_DATA, FilePath);
              return (false);
            }
            else
            {
              if (_ExeOutSize > 0)
              {
            // self-executable file
            fs.Seek(_ExeOutSize + 36, SeekOrigin.Begin);
              }
              else
              {
            fs.Seek(36, SeekOrigin.Begin);
              }
            }

            try
            {
              // The Header of MemoryStream is encrypted
              using (Rijndael aes = new RijndaelManaged())
              {
            aes.BlockSize = 256;             // BlockSize = 32 bytes
            aes.KeySize = 256;               // KeySize = 32 bytes
            aes.Mode = CipherMode.CBC;       // CBC mode
            aes.Padding = PaddingMode.Zeros; // Padding mode is "ZEROS".

            aes.Key = key;
            aes.IV = iv;

            // Decryption interface.
            ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
            using (CryptoStream cse = new CryptoStream(fs, decryptor, CryptoStreamMode.Read))
            {
              using (MemoryStream ms = new MemoryStream())
              {
                byteArray = new byte[_AtcHeaderSize];
                len = cse.Read(byteArray, 0, _AtcHeaderSize);
                ms.Write(byteArray, 0, _AtcHeaderSize);
            #if (DEBUG)
                //string AppDirPath = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
                string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                string TempFilePath = Path.Combine(DesktopPath, "decrypt_header.txt");
                using (StreamWriter sw = new StreamWriter(TempFilePath, false, Encoding.UTF8))
                {
                  sw.Write(Encoding.UTF8.GetString(byteArray));
                }
            #endif
                // Check Password Token
                if (Encoding.UTF8.GetString(byteArray).IndexOf(AtC_ENCRYPTED_TOKEN) > -1)
                {
                  // Decryption is succeeded.
                }
                else
                {
                  // Token is not match ( Password is not correct )
                  e.Result = new FileDecryptReturnVal(PASSWORD_TOKEN_NOT_FOUND, FilePath);
                  return (false);
                }

                ms.Position = 0;

                var sr = new StreamReader(ms, Encoding.UTF8);
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                  if (Regex.IsMatch(line, @"^[0-9]+:"))
                  {
                    FileList.Add(line);
                  }
                }

              }//end using (MemoryStream ms = new MemoryStream())

            }//end using (CryptoStream cse = new CryptoStream(fs, decryptor, CryptoStreamMode.Read));

              }//end using (Rijndael aes = new RijndaelManaged());

            }
            catch
            {
              e.Result = new FileDecryptReturnVal(ERROR_UNEXPECTED, "");
              return (false);
            }

              }//end using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read));

              //----------------------------------------------------------------------
              // Make a list array of the information for each file
              //----------------------------------------------------------------------
              _TotalFileSize = 0;
              string ParentFolder = "";
              bool fDirectoryTraversal = false;
              string InvalidFilePath = "";
              FileList.ForEach(delegate (string OutputLine)
              {
            int LastWriteDate, CreateDate;
            double LastWriteTime, CreateTime;
            DateTime LastWriteDateTime = DateTime.Parse("0001/01/01");
            DateTime CreationDateTime = DateTime.Parse("0001/01/01");

            FileListData fd = new FileListData();
            string[] OutputFileData = OutputLine.Split('\t');

            //-----------------------------------
            // File number
            //
            int FileNum;
            // e.g.)
            // 0:sample.txt[\t]49657[\t]32[\t]736194[\t]39585.875[\t]736194[\t]30186.782[\t]5f43aa1fed05350f34c2fabb7ed938457b2497f2b54a50415b51882f333b8ae1
            string[] FilePathSplits = OutputFileData[0].Split(':');
            if (Int32.TryParse(FilePathSplits[0], out FileNum) == false)
            {
              FileNum = -1;
            }
            //-----------------------------------
            // ディレクトリ・トラバーサル対策
            // Directory traversal countermeasures
            if (OutputFileData[0].IndexOf(@"..\") >= 0)
            {
              fDirectoryTraversal = true;
              InvalidFilePath = OutputFileData[0];
            }

            //-----------------------------------
            // Parent folder is not created.
            //
            if (_fNoParentFolder == true)
            {
              if (FileNum == 0)
              {
            if(FilePathSplits.Length > 2)  // ルートディレクトリ(ex. 0:G:\Test.txt)
            {
              ParentFolder = FilePathSplits[2];
            }
            else
            {
              ParentFolder = FilePathSplits[1];
            }
              }
              else
              {
            if (FilePathSplits.Length > 2)  // ルートディレクトリ
            {
              StringBuilder sb = new StringBuilder(FilePathSplits[2]);
              len = ParentFolder.Length;
              FilePathSplits[2] = sb.Replace(ParentFolder, "", 0, len).ToString();
            }
            else
            {
              StringBuilder sb = new StringBuilder(FilePathSplits[1]);
              len = ParentFolder.Length;
              FilePathSplits[1] = sb.Replace(ParentFolder, "", 0, len).ToString();
            }
              }
            }

            //-----------------------------------
            // File path
            //
            string OutFilePath = "";
            if (_fSalvageIntoSameDirectory == true) // Salvage mode?
            {
              OutFilePath = Path.Combine(OutDirPath, Path.GetFileName(FilePathSplits[1]));
            }
            else
            {
              if(FilePathSplits.Length > 2)
              {
            OutFilePath = Path.Combine(OutDirPath, FilePathSplits[2]);
              }
              else
              {
            OutFilePath = Path.Combine(OutDirPath, FilePathSplits[1]);
              }
            }
            fd.FilePath = OutFilePath;

            //-----------------------------------
            // File size
            if (Int64.TryParse(OutputFileData[1], out fd.FileSize) == false)
            {
              fd.FileSize = -1;
            }
            else
            {
              _TotalFileSize += fd.FileSize;
            }
            //-----------------------------------
            // File attribute
            if (Int32.TryParse(OutputFileData[2], out fd.FileAttribute) == false)
            {
              fd.FileAttribute = -1;
            }

            /*
                    * TTimeStamp = record
                    *  Time: Integer;      { Number of milliseconds since midnight }
                    *  Date: Integer;      { One plus number of days since 1/1/0001 }
                    * end;
                */
            //-----------------------------------
            // Last update timestamp
            if (_fSameTimeStamp == false && Int32.TryParse(OutputFileData[3], out LastWriteDate) == true)
            {
              LastWriteDateTime = LastWriteDateTime.AddDays(LastWriteDate); // Add days
            }
            else
            {
              LastWriteDateTime = DateTime.Now;
            }

            if (_fSameTimeStamp == false && Double.TryParse(OutputFileData[4], out LastWriteTime) == true)
            {
              LastWriteDateTime = LastWriteDateTime.AddSeconds(LastWriteTime);  // Add seconds
            }
            else
            {
              LastWriteDateTime = DateTime.Now;
            }

            fd.LastWriteDateTime = LastWriteDateTime;

            //-----------------------------------
            // Create datetime
            if (_fSameTimeStamp == false && Int32.TryParse(OutputFileData[5], out CreateDate) == true)
            {
              CreationDateTime = CreationDateTime.AddDays(CreateDate);
            }
            else
            {
              CreationDateTime = DateTime.Now;
            }

            if (_fSameTimeStamp == false && Double.TryParse(OutputFileData[6], out CreateTime) == true)
            {
              CreationDateTime = CreationDateTime.AddSeconds(CreateTime);
            }
            else
            {
              CreationDateTime = DateTime.Now;
            }

            fd.CreationDateTime = CreationDateTime;

            //-----------------------------------
            // SHA-256 hash
            if (OutputFileData.Length > 7)
            {
              fd.Hash = OutputFileData[7];
            }

            //-----------------------------------
            // Insert to 'Key-Value' type array data.
            dic.Add(FileNum, fd);

              });

              // Directory traversal countermeasures
              if (fDirectoryTraversal == true)
              {
            e.Result = new FileDecryptReturnVal(INVALID_FILE_PATH, InvalidFilePath);
            return(false);
              }

              //----------------------------------------------------------------------
              // Check the disk space
              //----------------------------------------------------------------------
              string RootDriveLetter = Path.GetPathRoot(OutDirPath).Substring(0, 1);

              if (RootDriveLetter == "\\")
              {
            // Network
              }
              else
              {
            DriveInfo drive = new DriveInfo(RootDriveLetter);

            DriveType driveType = drive.DriveType;
            switch (driveType)
            {
              case DriveType.CDRom:
              case DriveType.NoRootDirectory:
              case DriveType.Unknown:
            break;
              case DriveType.Fixed:     // Local Drive
              case DriveType.Network:   // Mapped Drive
              case DriveType.Ram:       // Ram Drive
              case DriveType.Removable: // Usually a USB Drive

            // The drive is not available, or not enough free space.
            if (drive.IsReady == false || drive.AvailableFreeSpace < _TotalFileSize)
            {
              e.Result = new FileDecryptReturnVal(NO_DISK_SPACE, drive.ToString(), _TotalFileSize, drive.AvailableFreeSpace);
              return (false);
            }
            break;
            }
              }

              //-----------------------------------
              // Decrypt file main data.
              //-----------------------------------
              try
              {
            using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
              //-----------------------------------
              // Adjust the header data in 32 bytes
              int mod = _AtcHeaderSize % 32;
              if (_fExecutableType == true)
              {
            fs.Seek(_ExeOutSize + 36 + _AtcHeaderSize + 32 - mod, SeekOrigin.Begin);
              }
              else
              {
            fs.Seek(36 + _AtcHeaderSize + 32 - mod, SeekOrigin.Begin);
              }

              //-----------------------------------
              // Decyption
              using (Rijndael aes = new RijndaelManaged())
              {
            aes.BlockSize = 256;             // BlockSize = 32bytes
            aes.KeySize = 256;               // KeySize = 32bytes
            aes.Mode = CipherMode.CBC;       // CBC mode
            aes.Padding = PaddingMode.Zeros; // Padding mode
            aes.Key = key;
            aes.IV = iv;
            #if (DEBUG)
            //System.Windows.Forms.MessageBox.Show("dic.Count: " + dic.Count);
            #endif
            //Decryption interface.
            ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
            using (CryptoStream cse = new CryptoStream(fs, decryptor, CryptoStreamMode.Read))
            {
              using (Ionic.Zlib.DeflateStream ds = new Ionic.Zlib.DeflateStream(cse, Ionic.Zlib.CompressionMode.Decompress))
              {
                /*
                public struct FileListData
                {
                  public string FilePath;
                  public Int64 FileSize;
                  public int FileAttribute;
                  public DateTime LastWriteDateTime;
                  public DateTime CreationDateTime;
                  public string Sha256String;
                }
                */
                FileStream outfs = null;
                Int64 FileSize = 0;
                int FileIndex = 0;

                bool fSkip = false;

                if (_fNoParentFolder == true)
                {
                  if (dic[0].FilePath.EndsWith("\\") == true)
                  {
                    FileIndex = 1;  // Ignore parent folder.
                  }
                }

                //----------------------------------------------------------------------
                byteArray = new byte[BUFFER_SIZE];

                //while ((len = ds.Read(byteArray, 0, BUFFER_SIZE)) > 0)
                while(true)
                {
                  if (_AppVersion < 3013)
                  {
                    len = cse.Read(byteArray, 0, BUFFER_SIZE);
                  }
                  else
                  {
                    len = ds.Read(byteArray, 0, BUFFER_SIZE);
                  }

                  // 末尾の0バイトファイル、またはフォルダ生成対策
                  if (len == 0) len = 1;

                  int buffer_size = len;

                  while (len > 0)
                  {
                    //----------------------------------------------------------------------
                    // 書き込み中のファイルまたはフォルダが無い場合は作る
                    // Create them if there is no writing file or folder.
                    //----------------------------------------------------------------------
                    if (outfs == null)
                    {
                      //-----------------------------------
                      // Create file or dirctories.
                      if (dic.ContainsKey(FileIndex) == false)
                      {
                        if (FileIndex > dic.Count - 1)
                        {
                          e.Result = new FileDecryptReturnVal(DECRYPT_SUCCEEDED);
                          return (true);
                        }
                        else
                        {
                          e.Result = new FileDecryptReturnVal(FILE_INDEX_NOT_FOUND, FileIndex);
                          return (false);
                        }
                      }
                      else
                      {
                        //-----------------------------------
                        // Create directory
                        //-----------------------------------
                        if (dic[FileIndex].FilePath.EndsWith("\\") == true)
                        {
                          string path = Path.Combine(OutDirPath, dic[FileIndex].FilePath);
                          DirectoryInfo di = new DirectoryInfo(path);

                          // File already exists.
                          if (Directory.Exists(path) == true)
                          {
                            // Temporary option for overwriting
                            // private const int USER_CANCELED  = -1;
                            // private const int OVERWRITE      = 1;
                            // private const int OVERWRITE_ALL  = 2;
                            // private const int KEEP_NEWER     = 3;
                            // private const int KEEP_NEWER_ALL = 4;
                            // private const int SKIP           = 5;
                            // private const int SKIP_ALL       = 6;
                            if (_TempOverWriteOption == OVERWRITE_ALL)
                            {
                              // Overwrite ( New create )
                            }
                            else if (_TempOverWriteOption == SKIP_ALL)
                            {
                              fSkip = true;
                            }
                            else if (_TempOverWriteOption == KEEP_NEWER_ALL)
                            {
                              if (di.LastWriteTime > dic[FileIndex].LastWriteDateTime)
                              {
                                fSkip = true; // old directory
                              }
                            }
                            else
                            {
                              // Show dialog of comfirming to overwrite.
                              dialog(0, path);

                              // Cancel
                              if (_TempOverWriteOption == USER_CANCELED)
                              {
                                e.Result = new FileDecryptReturnVal(USER_CANCELED);
                                return (false);
                              }
                              else if (_TempOverWriteOption == OVERWRITE || _TempOverWriteOption == OVERWRITE_ALL)
                              {
                                // Overwrite ( New create )
                              }
                              // Skip, or Skip All
                              else if (_TempOverWriteOption == SKIP_ALL)
                              {
                                fSkip = true;
                                e.Result = new FileDecryptReturnVal(DECRYPT_SUCCEEDED);
                                return (true);
                              }
                              else if (_TempOverWriteOption == SKIP)
                              {
                                fSkip = true;
                              }
                              else if (_TempOverWriteOption == KEEP_NEWER || _TempOverWriteOption == KEEP_NEWER_ALL)
                              { // New file?
                                if (di.LastWriteTime > dic[FileIndex].LastWriteDateTime)
                                {
                                  fSkip = true;
                                }
                              }
                            }

                            if ( fSkip == false)
                            {
                              //隠し属性を削除する
                              di.Attributes &= ~FileAttributes.Hidden;
                              //読み取り専用を削除
                              di.Attributes &= ~FileAttributes.ReadOnly;
                            }

                            //すべての属性を解除
                            //File.SetAttributes(path, FileAttributes.Normal);

                          } // end if ( Directory.Exists )

                          Directory.CreateDirectory(dic[FileIndex].FilePath);
                          _OutputFileList.Add(dic[FileIndex].FilePath);
                          FileSize = 0;
                          FileIndex++;

                          if (FileIndex > dic.Count - 1)
                          {
                            e.Result = new FileDecryptReturnVal(DECRYPT_SUCCEEDED);
                            return (true);
                          }

                          continue;

                        }
                        //-----------------------------------
                        // Create file
                        //-----------------------------------
                        else
                        {
                          string path = Path.Combine(OutDirPath, dic[FileIndex].FilePath);
                          FileInfo fi = new FileInfo(path);

                          // File already exists.
                          if (File.Exists(path) == true)
                          {
                            // Salvage Data Mode
                            if (_fSalvageIntoSameDirectory == true)
                            {
                              int SerialNum = 0;
                              while (File.Exists(path) == true)
                              {
                                path = getFileNameWithSerialNumber(path, SerialNum);
                                SerialNum++;
                              }
                            }
                            else
                            {
                              // Temporary option for overwriting
                              // private const int USER_CANCELED  = -1;
                              // private const int OVERWRITE      = 1;
                              // private const int OVERWRITE_ALL  = 2;
                              // private const int KEEP_NEWER     = 3;
                              // private const int KEEP_NEWER_ALL = 4;
                              // private const int SKIP           = 5;
                              // private const int SKIP_ALL       = 6;
                              if (_TempOverWriteOption == OVERWRITE_ALL)
                              {
                                // Overwrite ( New create )
                              }
                              else if (_TempOverWriteOption == SKIP_ALL)
                              {
                                fSkip = true;
                              }
                              else if (_TempOverWriteOption == KEEP_NEWER_ALL)
                              {
                                if (fi.LastWriteTime > dic[FileIndex].LastWriteDateTime)
                                {
                                  fSkip = true;
                                }
                              }
                              else
                              {
                                // Show dialog of comfirming to overwrite.
                                dialog(0, path);

                                // Cancel
                                if (_TempOverWriteOption == USER_CANCELED)
                                {
                                  e.Result = new FileDecryptReturnVal(USER_CANCELED);
                                  return (false);
                                }
                                else if (_TempOverWriteOption == OVERWRITE || _TempOverWriteOption == OVERWRITE_ALL)
                                {
                                  // Overwrite ( New create )
                                }
                                // Skip, or Skip All
                                else if (_TempOverWriteOption == SKIP || _TempOverWriteOption == SKIP_ALL)
                                {
                                  fSkip = true;
                                }
                                else if (_TempOverWriteOption == KEEP_NEWER || _TempOverWriteOption == KEEP_NEWER_ALL)
                                { // New file?
                                  if (fi.LastWriteTime > dic[FileIndex].LastWriteDateTime)
                                  {
                                    fSkip = true; // old directory
                                  }
                                }
                              }

                              if (fSkip == false)
                              {
                                //隠し属性を削除する
                                //fi.Attributes &= ~FileAttributes.Hidden;
                                //読み取り専用を削除
                                //fi.Attributes &= ~FileAttributes.ReadOnly;

                                //すべての属性を解除
                                File.SetAttributes(path, FileAttributes.Normal);

                              }

                            }

                          }// end if ( File.Exists );

                          // Salvage data mode
                          // サルベージ・モード
                          if (_fSalvageToCreateParentFolderOneByOne == true)
                          {
                            // Decrypt one by one while creating the parent folder.
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                          }

                          if ( fSkip == true)
                          {
                            // Not create file
                          }
                          else
                          {
                            outfs = new FileStream(path, FileMode.Create, FileAccess.Write);
                          }

                          _OutputFileList.Add(path);
                          FileSize = 0;

                        }

                      }

                    }// end if (outfs == null);

                    //----------------------------------------------------------------------
                    // Write data
                    //----------------------------------------------------------------------
                    if (FileSize + len < (Int64)dic[FileIndex].FileSize)
                    {
                      if (outfs != null || fSkip == true)
                      {
                        // まだまだ書き込める
                        // can write more
                        if (fSkip == false)
                        {
                          outfs.Write(byteArray, buffer_size - len, len);
                        }
                        FileSize += len;
                        _TotalSize += len;
                        len = 0;
                      }
                    }
                    else
                    {
                      // ファイルの境界を超えて読み込んでいる
                      // Reading beyond file boundaries
                      int rest = (int)(dic[FileIndex].FileSize - FileSize);

                      if (fSkip == false)
                      {
                        // 書き込み完了
                        // Write completed
                        outfs.Write(byteArray, buffer_size - len, rest);
                      }

                      _TotalSize += rest;

                      len -= rest;

                      if (outfs != null)
                      {
                        // 生成したファイルを閉じる
                        // File close
                        outfs.Close();
                        outfs = null;
                      }

                      //----------------------------------------------------------------------
                      // ファイル属性の復元
                      // Restore file attributes

                      if (fSkip == false)
                      {
                        FileInfo fi = new FileInfo(dic[FileIndex].FilePath);
                        // タイムスタンプの復元
                        // Restore the timestamp of a file
                        fi.CreationTime = (DateTime)dic[FileIndex].CreationDateTime;
                        fi.LastWriteTime = (DateTime)dic[FileIndex].LastWriteDateTime;
                        // ファイル属性の復元
                        // Restore file attribute.
                        fi.Attributes = (FileAttributes)dic[FileIndex].FileAttribute;

                        // ハッシュ値のチェック
                        // Check the hash of a file
                        string hash = GetSha256HashFromFile(dic[FileIndex].FilePath);
                        if (hash != dic[FileIndex].Hash.ToString())
                        {
                          e.Result = new FileDecryptReturnVal(NOT_CORRECT_HASH_VALUE, dic[FileIndex].FilePath);
                          return (false);
                        }
                      }

                      FileSize = 0;
                      FileIndex++;

                      fSkip = false;

                      if (FileIndex > dic.Count - 1)
                      {
                        e.Result = new FileDecryptReturnVal(DECRYPT_SUCCEEDED);
                        return (true);
                      }

                    }
                    //----------------------------------------------------------------------
                    //進捗の表示
                    string MessageText = "";
                    if (_TotalNumberOfFiles > 1)
                    {
                      MessageText = FilePath + " ( " + _NumberOfFiles.ToString() + "/" + _TotalNumberOfFiles.ToString() + " files" + " )";
                    }
                    else
                    {
                      MessageText = FilePath;
                    }

                    MessageList = new ArrayList();
                    MessageList.Add(DECRYPTING);
                    MessageList.Add(MessageText);
                    float percent = ((float)_TotalSize / _TotalFileSize);
                    worker.ReportProgress((int)(percent * 10000), MessageList);

                    // User cancel
                    if (worker.CancellationPending == true)
                    {
                      if (outfs != null)
                      {
                        outfs.Close();
                        outfs = null;
                      }
                      e.Cancel = true;
                      return (false);
                    }

                  }// end while(len > 0);

                }// end while ((len = ds.Read(byteArray, 0, BUFFER_SIZE)) > 0);

              }// end using (DeflateStream ds = new DeflateStream(cse, CompressionMode.Decompress));

            }// end using (CryptoStream cse = new CryptoStream(fs, decryptor, CryptoStreamMode.Read));

              }// end using (Rijndael aes = new RijndaelManaged());

            }// end using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read));

              }
              catch (Exception ex)
              {
            #if (DEBUG)
            System.Windows.Forms.MessageBox.Show("Exception!");
            #endif

            System.Windows.Forms.MessageBox.Show(ex.Message);

            e.Result = new FileDecryptReturnVal(ERROR_UNEXPECTED);
            return (false);

              }

              e.Result = new FileDecryptReturnVal(DECRYPT_SUCCEEDED);
              return (true);
        }