예제 #1
0
		private void checkBoxMyDecodePasswordKeep_CheckedChanged(object sender, EventArgs e)
		{
			if (fLoading == true)
			{
				return;
			}

			if (checkBoxMyDecodePasswordKeep.Checked == true)
			{
				// Show Option form
				Form4 frm4 = new Form4("DecryptPassword", "");
				frm4.ShowDialog();
				frm4.Dispose();

				if (AppSettings.Instance.MyDecryptPasswordString == "")
				{
					textBoxMyDecodePassword.Text = "";
					checkBoxMyDecodePasswordKeep.Checked = false;

          if (checkBoxMyEncodePasswordKeep.Checked == false)
          {
            checkBoxDobyMemorizedPassword.Checked = false;
            checkBoxDobyMemorizedPassword.Enabled = false;
          }
        }
				else
				{
					//textBoxMyEncodePassword.Text = new string('*', AppSettings.Instance.MyEncryptPasswordString.Length);
					textBoxMyDecodePassword.Text = new string('*', 16);

          //checkBoxDobyMemorizedPassword.Checked = true;
          checkBoxDobyMemorizedPassword.Enabled = true;
        }
      }

      buttonApply.Enabled = true;

		}
예제 #2
0
        //======================================================================
        /// <summary>
        /// 
        /// </summary>
        private void EncryptionProcess()
        {
            //-----------------------------------
              // Display progress window
              //-----------------------------------
              panelStartPage.Visible = false;
              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = false;
              panelProgressState.Visible = true;
              labelCryptionType.Text = Resources.labelProcessNameEncrypt;

              if (FileIndex > AppSettings.Instance.FileList.Count - 1)
              {
            labelProgressPercentText.Text = "100%";
            progressBar.Style = ProgressBarStyle.Continuous;
            progressBar.Value = progressBar.Maximum;
            labelCryptionType.Text = "";
            labelProgressMessageText.Text = Resources.labelCaptionCompleted;  // "Completed"
            notifyIcon1.Text = "100% " + Resources.labelCaptionCompleted;

            buttonCancel.Text = Resources.ButtonTextOK;
            return;
              }

              //-----------------------------------
              // Directory to oputput encrypted files
              //-----------------------------------
              //string OutDirPath = Path.GetDirectoryName(AppSettings.Instance.FileList[0]);  // default
              string OutDirPath = "";
              if (AppSettings.Instance.fSaveToSameFldr == true)
              {
            OutDirPath = AppSettings.Instance.SaveToSameFldrPath;
              }
              else
              {
            string FullPath = Path.GetFullPath(AppSettings.Instance.FileList[FileIndex]);
            if (Directory.Exists(Path.GetDirectoryName(FullPath)) == true)
            {
              OutDirPath = Path.GetDirectoryName(FullPath);
            }
              }

              if (Directory.Exists(OutDirPath) == false)
              {
            // 注意
            // 保存先のフォルダーが見つかりません! 処理を中止します。
            //
            // Alert
            // The folder to save is not found! Process is aborted.
            DialogResult ret = MessageBox.Show(new Form { TopMost = true }, Resources.DialogMessageDirectoryNotFount + Environment.NewLine + OutDirPath,
            Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
              }

              //-----------------------------------
              // Encrypted files camouflage with extension
              //-----------------------------------
              string Extension = "";
              if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC || AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE)
              {
            Extension = AppSettings.Instance.fAddCamoExt == true ? AppSettings.Instance.CamoExt : ".atc";
              }
              else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
              {
            Extension = AppSettings.Instance.fAddCamoExt == true ? AppSettings.Instance.CamoExt : ".exe";
              }
              else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
              {
            Extension = AppSettings.Instance.fAddCamoExt == true ? AppSettings.Instance.CamoExt : ".zip";
              }

              //-----------------------------------
              // Encryption password
              //-----------------------------------
              string EncryptionPassword = "";

              if (AppSettings.Instance.fMyEncryptPasswordKeep == true)
              {
            EncryptionPassword = AppSettings.Instance.MyEncryptPasswordString;
              }
              else
              {
            EncryptionPassword = textBoxRePassword.Text;
              }

              //-----------------------------------
              // Password file
              //-----------------------------------
              // ※パスワードファイルは、記憶パスワードや通常の入力されたパスワードよりも優先される。
              // * This password files is priority than memorized encryption password and inputting normal password string.
              byte[] EncryptionPasswordBinary = null;
              if (AppSettings.Instance.fAllowPassFile == true && AppSettings.Instance.EncryptionFileType != FILE_TYPE_PASSWORD_ZIP)  // ATC(EXE) only
              {
            // Check specified password file for Decryption
            if (AppSettings.Instance.fCheckPassFile == true)
            {
              if (File.Exists(AppSettings.Instance.PassFilePath) == true)
              {
            EncryptionPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.PassFilePath);
              }
              else
              {
            if (AppSettings.Instance.fNoErrMsgOnPassFile == false)
            {
              // エラー
              // 暗号化時に指定されたパスワードファイルが見つかりません。
              //
              // Error
              // The specified password file is not found in encryption.
              DialogResult ret = MessageBox.Show(
                new Form { TopMost = true },
                Resources.DialogMessageEncryptionPasswordFileNotFound + Environment.NewLine + AppSettings.Instance.PassFilePath,
                Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return;
              }
            }

            // Drag & Drop Password file
            if (File.Exists(AppSettings.Instance.TempEncryptionPassFilePath) == true)
            {
              EncryptionPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.TempEncryptionPassFilePath);
            }
              }

              //-----------------------------------
              // Always minimize when running
              //-----------------------------------
              if (AppSettings.Instance.fMainWindowMinimize == true)
              {
            this.WindowState = FormWindowState.Minimized;
              }

              //-----------------------------------
              // Minimizing a window without displaying in the taskbar
              //-----------------------------------
              if (AppSettings.Instance.fTaskBarHide == true)
              {
            this.Hide();
              }

              //-----------------------------------
              // Display in the task tray
              //-----------------------------------
              if (AppSettings.Instance.fTaskTrayIcon == true)
              {
            notifyIcon1.Visible = true;
              }
              else
              {
            notifyIcon1.Visible = false;
              }

              //-----------------------------------
              // Save same encryption type that was used to before.
              //-----------------------------------
              AppSettings.Instance.EncryptionSameFileTypeBefore = AppSettings.Instance.EncryptionFileType;

              //-----------------------------------
              // Get directory path to output
              //-----------------------------------
              string OutputDirPath = "";

              if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE || AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC)
              {
            pictureBoxProgress.Image = pictureBoxAtcOn.Image;
            labelProgress.Text = labelAtc.Text;

            // Save to the same directory?
            if (AppSettings.Instance.fSaveToSameFldr == true)
            {
              if (Directory.Exists(AppSettings.Instance.SaveToSameFldrPath) == true)
              {
            OutputDirPath = AppSettings.Instance.SaveToSameFldrPath;
              }
            }

              }
              else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
              {
            pictureBoxProgress.Image = pictureBoxExeOn.Image;
            labelProgress.Text = labelExe.Text;

            // Save to the same directory?
            if (AppSettings.Instance.fSaveToSameFldr == true)
            {
              if (Directory.Exists(AppSettings.Instance.SaveToSameFldrPath) == true)
              {
            OutputDirPath = AppSettings.Instance.SaveToSameFldrPath;
              }
            }
              }
              else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
              {
            pictureBoxProgress.Image = pictureBoxZipOn.Image;
            labelProgress.Text = labelZip.Text;

            // Save the zip file(s) to the same directory?
            if (AppSettings.Instance.fZipToSameFldr == true)
            {
              if (Directory.Exists(AppSettings.Instance.ZipToSameFldrPath) == true)
              {
            OutputDirPath = AppSettings.Instance.ZipToSameFldrPath;
              }
            }
              }

              string AtcFilePath = "";

              //----------------------------------------------------------------------
              // Create one encrypted file from files
              //----------------------------------------------------------------------
              if (AppSettings.Instance.fAllFilePack == true)
              {
            // 複数ファイルは一つの暗号化ファイルにまとめる
            // The multiple files are gotten one of the encrypted file together.
            //
            // 複数のファイルやフォルダーを処理すると、1つの暗号化ファイルにまとめます。
            // このオプションを選択している場合、新しいファイル名を指定します。
            // The multiple files is gotten one of the encrypted file together.
            // If this option is selected, you specify a new file name.
            if (AppSettings.Instance.fSaveToSameFldr == true && Directory.Exists(AppSettings.Instance.SaveToSameFldrPath) == true)
            {
              saveFileDialog1.FileName = Path.GetFileName(AppSettings.Instance.FileList[0]);
              saveFileDialog1.InitialDirectory = AppSettings.Instance.SaveToSameFldrPath;
            }
            else
            {
              saveFileDialog1.FileName = Path.GetFileName(AppSettings.Instance.FileList[0]);
              saveFileDialog1.InitialDirectory = AppSettings.Instance.InitDirPath;
            }

            // Input encrypted file name for putting together
            // 一つにまとめる暗号化ファイル名入力
            saveFileDialog1.Title = Resources.DialogTitleAllPackFiles;

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              saveFileDialog1.Filter = Resources.SaveDialogFilterSelfExeFiles;
            }
            else
            {
              saveFileDialog1.Filter = Resources.SaveDialogFilterAtcFiles;
            }

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
              AtcFilePath = saveFileDialog1.FileName;
              AppSettings.Instance.InitDirPath = Path.GetDirectoryName(saveFileDialog1.FileName);
            }
            else
            { //キャンセル(Cancel)
              panelStartPage.Visible = false;
              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = true;
              panelDecrypt.Visible = false;
              panelProgressState.Visible = false;
              return;
            }

            int NumberOfFiles = 0;

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3 = new FileEncrypt3();
              encryption3.NumberOfFiles = NumberOfFiles + 1;
              encryption3.TotalNumberOfFiles = NumberOfFiles;
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              compression = new ZipEncrypt();
              compression.NumberOfFiles = NumberOfFiles + 1;
              compression.TotalNumberOfFiles = NumberOfFiles;
            }

            //-----------------------------------
            //Set number of times to input password in encrypt files
            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              char input_limit;
              if (0 < AppSettings.Instance.MissTypeLimitsNum && AppSettings.Instance.MissTypeLimitsNum < 11)
              {
            input_limit = (char)AppSettings.Instance.MissTypeLimitsNum;
              }
              else
              {
            input_limit = (char)3;
              }
              encryption3.MissTypeLimits = input_limit;
            }

            //-----------------------------------
            // Save encryption files to same folder.
            if (AppSettings.Instance.fSaveToSameFldr == false)
            {
              OutputDirPath = Path.GetDirectoryName(AtcFilePath);
            }

            //-----------------------------------
            // Specify the format of the encryption file name
            string FileName = Path.GetFileName(AtcFilePath);
            if (AppSettings.Instance.fAutoName == true)
            {
              FileName = AppSettings.Instance.getSpecifyFileNameFormat(
            AppSettings.Instance.AutoNameFormatText, FileName, NumberOfFiles
              );
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //Create encrypted file including extension
            if (AppSettings.Instance.fExtInAtcFileName == true)
            {
              FileName = Path.GetFileName(AtcFilePath) + Extension;
            }
            else
            {
              FileName = Path.GetFileNameWithoutExtension(AtcFilePath) + Extension;
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //-----------------------------------
            //Confirm &overwriting when same file name exists.
            if ((encryption3 != null && AppSettings.Instance.fEncryptConfirmOverwrite == true) ||
            compression != null && AppSettings.Instance.fZipConfirmOverwrite == true)
            {
              if (File.Exists(AtcFilePath) == true)
              {
            // Show dialog for confirming to orverwrite

            if (TempOverWriteOption == SKIP_ALL)
            {
              FileIndex = AppSettings.Instance.FileList.Count;
              EncryptionProcess();
              return;
            }
            else if (TempOverWriteOption == OVERWRITE_ALL)
            {
              // Overwrite ( Create )
            }
            else
            {
              // 問い合わせ
              // 以下のファイルはすでに存在しています。上書きして保存しますか?
              //
              // Question
              // The following file already exists. Do you overwrite the files to save?
              using (Form4 frm4 = new Form4("ComfirmToOverwriteAtc",
                Resources.labelComfirmToOverwriteFile + Environment.NewLine + AtcFilePath))
              {
                frm4.ShowDialog();

                if (frm4.OverWriteOption == USER_CANCELED)
                {
                  panelStartPage.Visible = false;
                  panelEncrypt.Visible = false;
                  panelEncryptConfirm.Visible = false;
                  panelDecrypt.Visible = false;
                  panelProgressState.Visible = true;

                  // Canceled
                  labelProgressPercentText.Text = "- %";
                  progressBar.Value = 0;
                  labelCryptionType.Text = "";
                  notifyIcon1.Text = "- % " + Resources.labelCaptionCanceled;
                  AppSettings.Instance.FileList = null;

                  buttonCancel.Text = Resources.ButtonTextOK;

                  // Atc file is deleted
                  if (File.Exists(encryption3.AtcFilePath) == true)
                  {
                    FileSystem.DeleteFile(encryption3.AtcFilePath);
                  }

                  FileIndex = -1;

                  // 暗号化の処理はキャンセルされました。
                  // Encryption was canceled.
                  labelProgressMessageText.Text = Resources.labelEncryptionCanceled;
                  return;
                }
                else
                {
                  TempOverWriteOption = frm4.OverWriteOption;
                  if (frm4.OverWriteOption == SKIP)
                  {
                    FileIndex++;
                    EncryptionProcess();
                    return;
                  }
                }
              }

            }

              }

            }

            //-----------------------------------
            // Self executable file
            //-----------------------------------
            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3.fExecutable = true;
            }

            //-----------------------------------
            // Set the timestamp of encryption file to original files or directories
            //-----------------------------------
            encryption3.fKeepTimeStamp = AppSettings.Instance.fKeepTimeStamp;

            //-----------------------------------
            // View the Cancel button
            //-----------------------------------
            buttonCancel.Text = Resources.ButtonTextCancel;

            //-----------------------------------
            // Encryption start
            //-----------------------------------

            // BackgroundWorker event handler
            bkg = new BackgroundWorker();

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              bkg.DoWork += (s, d) =>
              encryption3.Encrypt(
            s, d,
            AppSettings.Instance.FileList.ToArray(),
            AtcFilePath,
            EncryptionPassword, EncryptionPasswordBinary,
            Path.GetFileNameWithoutExtension(AtcFilePath));
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              bkg.DoWork += (s, d) =>
              compression.Encrypt(
            s, d,
            AppSettings.Instance.FileList.ToArray(),
            AtcFilePath,
            EncryptionPassword, EncryptionPasswordBinary,
            Path.GetFileNameWithoutExtension(AtcFilePath));
            }

            FileIndex = AppSettings.Instance.FileList.Count;

            bkg.RunWorkerCompleted += backgroundWorker_Encryption_RunWorkerCompleted;
            bkg.ProgressChanged += backgroundWorker_ProgressChanged;
            bkg.WorkerReportsProgress = true;
            bkg.WorkerSupportsCancellation = true;

            bkg.RunWorkerAsync();

              }// end if (AppSettings.Instance.EncryptionFileType == TYPE_ATC_ENCRYPT && AllPackFilePath != "");
              //----------------------------------------------------------------------
              // Encrypt or decrypt files in directory one by one
              //----------------------------------------------------------------------
              else if (AppSettings.Instance.fFilesOneByOne == true)
              {
            // フォルダ内のファイルは個別に暗号化する
            // Files in the folder are encrypted one by one.
            //
            // フォルダーが処理された場合、サブフォルダー以下にあるファイルすべてを個別に暗号化します。
            // ただし、その中に既に暗号化ファイルか、ZIPファイルが含まれる場合は、それらを無視します。
            // If the folder has been processed, all the files in the subfolders are encrypted one by one.
            // However, if encrypted files or ZIP files were existed already in it, they are ignored.

            int TotalNumberOfFiles = AppSettings.Instance.FileList.Count();

            // A first file of ArrayList
            string FilePath = AppSettings.Instance.FileList[FileIndex];

            encryption3 = new FileEncrypt3();
            compression = new ZipEncrypt(); ;

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3.NumberOfFiles = FileIndex + 1;
              encryption3.TotalNumberOfFiles = TotalNumberOfFiles;
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              compression.NumberOfFiles = FileIndex + 1;
              compression.TotalNumberOfFiles = TotalNumberOfFiles;
            }

            //-----------------------------------
            // Save encryption files to same folder.
            if (AppSettings.Instance.fSaveToSameFldr == false)
            {
              OutputDirPath = Path.GetDirectoryName(FilePath);
            }

            //-----------------------------------
            // Specify the format of the encryption file name
            string FileName = Path.GetFileName(FilePath);
            if (AppSettings.Instance.fAutoName == true)
            {
              FileName = AppSettings.Instance.getSpecifyFileNameFormat(
            AppSettings.Instance.AutoNameFormatText, FileName, FileIndex + 1
              );
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //-----------------------------------
            //Create encrypted file including extension
            if (AppSettings.Instance.fExtInAtcFileName == true)
            {
              FileName = Path.GetFileName(AtcFilePath) + Extension;
            }
            else
            {
              FileName = Path.GetFileNameWithoutExtension(AtcFilePath) + Extension;
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //-----------------------------------
            //Confirm &overwriting when same file name exists.
            if ((encryption3 != null && AppSettings.Instance.fEncryptConfirmOverwrite == true) ||
            compression != null && AppSettings.Instance.fZipConfirmOverwrite == true)
            {
              if (File.Exists(AtcFilePath) == true)
              {
            // Show dialog for confirming to orverwrite

            if (TempOverWriteOption == SKIP_ALL)
            {
              FileIndex = AppSettings.Instance.FileList.Count;
              EncryptionProcess();
              return;
            }
            else if (TempOverWriteOption == OVERWRITE_ALL)
            {
              // Overwrite ( Create )
            }
            else
            {
              // 問い合わせ
              // 以下のファイルはすでに存在しています。上書きして保存しますか?
              //
              // Question
              // The following file already exists. Do you overwrite the files to save?
              using (Form4 frm4 = new Form4("ComfirmToOverwriteAtc",
                Resources.labelComfirmToOverwriteFile + Environment.NewLine + AtcFilePath))
              {
                frm4.ShowDialog();

                if (frm4.OverWriteOption == USER_CANCELED)
                {
                  panelStartPage.Visible = false;
                  panelEncrypt.Visible = false;
                  panelEncryptConfirm.Visible = false;
                  panelDecrypt.Visible = false;
                  panelProgressState.Visible = true;

                  // Canceled
                  labelProgressPercentText.Text = "- %";
                  progressBar.Value = 0;
                  labelCryptionType.Text = "";
                  notifyIcon1.Text = "- % " + Resources.labelCaptionCanceled;
                  AppSettings.Instance.FileList = null;

                  buttonCancel.Text = Resources.ButtonTextOK;

                  // Atc file is deleted
                  if (File.Exists(encryption3.AtcFilePath) == true)
                  {
                    FileSystem.DeleteFile(encryption3.AtcFilePath);
                  }

                  FileIndex = -1;

                  // 暗号化の処理はキャンセルされました。
                  // Encryption was canceled.
                  labelProgressMessageText.Text = Resources.labelEncryptionCanceled;
                  return;
                }
                else
                {
                  TempOverWriteOption = frm4.OverWriteOption;
                  if (frm4.OverWriteOption == SKIP)
                  {
                    FileIndex++;
                    EncryptionProcess();
                    return;
                  }
                }
              }

            }

              }

            }

            //-----------------------------------
            // Self executable file
            //-----------------------------------
            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3.fExecutable = true;
            }

            //-----------------------------------
            // Set the timestamp of encryption file to original files or directories
            //-----------------------------------
            encryption3.fKeepTimeStamp = AppSettings.Instance.fKeepTimeStamp;

            //-----------------------------------
            // View the Cancel button
            //-----------------------------------
            buttonCancel.Text = Resources.ButtonTextCancel;

            //-----------------------------------
            // Encryption start
            //-----------------------------------

            bkg = new BackgroundWorker();

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              bkg.DoWork += (s, d) =>
              {
            encryption3.Encrypt(
              s, d,
              new string[] { AppSettings.Instance.FileList[FileIndex] },
              AtcFilePath,
              EncryptionPassword, EncryptionPasswordBinary,
              "");
              };
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              bkg.DoWork += (s, d) =>
              {
            compression.Encrypt(
              null, null,
              new string[] { AppSettings.Instance.FileList[FileIndex] },
              AtcFilePath,
              EncryptionPassword, EncryptionPasswordBinary,
              "");
              };
            }

            bkg.RunWorkerCompleted += backgroundWorker_Encryption_RunWorkerCompleted;
            bkg.ProgressChanged += backgroundWorker_ProgressChanged;
            bkg.WorkerReportsProgress = true;
            bkg.WorkerSupportsCancellation = true;

            bkg.RunWorkerAsync();

              }// end else if (AppSettings.Instance.fFilesOneByOne == true);

              //----------------------------------------------------------------------
              // Normal
              //----------------------------------------------------------------------
              else
              { // AppSettings.Instance.fNormal;

            // 何もしない
            // Nothing to do
            //
            // 複数のファイルやフォルダーを処理すると、それぞれを暗号化しファイルが生成されます。
            // フォルダーの場合は、サブフォルダーも含め、フォルダー単位でパックされます。
            // When a number of files and folders is processed, and each file is generated to encrypt files.
            // In the case of folders ( including subfolders ) are packed in a folder unit.

            int TotalNumberOfFiles = AppSettings.Instance.FileList.Count();

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3 = new FileEncrypt3();
              encryption3.NumberOfFiles = FileIndex + 1;
              encryption3.TotalNumberOfFiles = TotalNumberOfFiles;
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              compression = new ZipEncrypt();
              compression.NumberOfFiles = FileIndex + 1;
              compression.TotalNumberOfFiles = TotalNumberOfFiles;
            }

            //-----------------------------------
            // Save encryption files to same folder.
            if (AppSettings.Instance.fSaveToSameFldr == false)
            {
              OutputDirPath = Path.GetDirectoryName(AppSettings.Instance.FileList[FileIndex]);
            }

            //-----------------------------------
            // Specify the format of the encryption file name
            string FileName = Path.GetFileName(AppSettings.Instance.FileList[FileIndex]);
            if (AppSettings.Instance.fAutoName == true)
            {
              FileName = AppSettings.Instance.getSpecifyFileNameFormat(
            AppSettings.Instance.AutoNameFormatText, FileName, FileIndex + 1
              );
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //Create encrypted file including extension
            if (AppSettings.Instance.fExtInAtcFileName == true)
            {
              FileName = Path.GetFileName(AtcFilePath) + Extension;
            }
            else
            {
              FileName = Path.GetFileNameWithoutExtension(AtcFilePath) + Extension;
            }

            AtcFilePath = Path.Combine(OutputDirPath, FileName);

            //-----------------------------------
            //Confirm &overwriting when same file name exists.

            if ((encryption3 != null && AppSettings.Instance.fEncryptConfirmOverwrite == true) ||
            compression != null && AppSettings.Instance.fZipConfirmOverwrite == true)
            {

              if (File.Exists(AtcFilePath) == true)
            {
            // Show dialog for confirming to orverwrite

            if (TempOverWriteOption == SKIP_ALL)
            {
              FileIndex++;
              EncryptionProcess();
              return;
            }
            else if (TempOverWriteOption == OVERWRITE_ALL)
            {
              // Overwrite ( Create )
            }
            else
            {
              // 問い合わせ
              // 以下のファイルはすでに存在しています。上書きして保存しますか?
              //
              // Question
              // The following file already exists. Do you overwrite the files to save?
              using (Form4 frm4 = new Form4("ComfirmToOverwriteAtc",
                Resources.labelComfirmToOverwriteFile + Environment.NewLine + AtcFilePath))
              {
                frm4.ShowDialog();

                if (frm4.OverWriteOption == USER_CANCELED)
                {
                  panelStartPage.Visible = false;
                  panelEncrypt.Visible = false;
                  panelEncryptConfirm.Visible = false;
                  panelDecrypt.Visible = false;
                  panelProgressState.Visible = true;

                  // Canceled
                  labelProgressPercentText.Text = "- %";
                  progressBar.Value = 0;
                  labelCryptionType.Text = "";
                  notifyIcon1.Text = "- % " + Resources.labelCaptionCanceled;
                  AppSettings.Instance.FileList = null;

                  buttonCancel.Text = Resources.ButtonTextOK;

                  // Atc file is deleted
                  if (File.Exists(encryption3.AtcFilePath) == true)
                  {
                    FileSystem.DeleteFile(encryption3.AtcFilePath);
                  }

                  FileIndex = -1;

                  // 暗号化の処理はキャンセルされました。
                  // Encryption was canceled.
                  labelProgressMessageText.Text = Resources.labelEncryptionCanceled;
                  return;
                }
                else
                {
                  TempOverWriteOption = frm4.OverWriteOption;
                  if (frm4.OverWriteOption == SKIP)
                  {
                    FileIndex++;
                    EncryptionProcess();
                    return;
                  }
                }
              }

            }

              }

            }
            //----------------------------------------------------------------------
            // Self executable file
            //----------------------------------------------------------------------
            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3.fExecutable = true;
            }

            //-----------------------------------
            // Set the timestamp of encryption file to original files or directories
            //-----------------------------------
            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              encryption3.fKeepTimeStamp = AppSettings.Instance.fKeepTimeStamp;
            }

            //-----------------------------------
            // View the Cancel button
            //-----------------------------------
            buttonCancel.Text = Resources.ButtonTextCancel;

            //----------------------------------------------------------------------
            // Encrypt
            //----------------------------------------------------------------------

            // BackgroundWorker event handler
            bkg = new BackgroundWorker();

            if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_NONE ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC ||
            AppSettings.Instance.EncryptionFileType == FILE_TYPE_ATC_EXE)
            {
              bkg.DoWork += (s, d) =>
              encryption3.Encrypt(
            s, d,
            new string[] { AppSettings.Instance.FileList[FileIndex] },
            AtcFilePath,
            EncryptionPassword, EncryptionPasswordBinary,
            "");
            }
            else if (AppSettings.Instance.EncryptionFileType == FILE_TYPE_PASSWORD_ZIP)
            {
              bkg.DoWork += (s, d) =>
              compression.Encrypt(
            s, d,
            new string[] { AppSettings.Instance.FileList[FileIndex] },
            AtcFilePath,
            EncryptionPassword, EncryptionPasswordBinary,
            "");
            }

            bkg.RunWorkerCompleted += backgroundWorker_Encryption_RunWorkerCompleted;
            bkg.ProgressChanged += backgroundWorker_ProgressChanged;
            bkg.WorkerReportsProgress = true;
            bkg.WorkerSupportsCancellation = true;

            bkg.RunWorkerAsync();

              }
        }
예제 #3
0
        private void StartProcess()
        {
            int ProcessType = 0;
              TempOverWriteOption = -1;

              labelPassword.Text = Resources.labelPassword;
              labelInputPasswordAgain.Text = Resources.labelInputPasswordAgainToConfirm;

              textBoxPassword.Enabled = true;
              textBoxPassword.BackColor = SystemColors.Window;
              textBoxPassword.Text = "";
              textBoxRePassword.Enabled = true;
              textBoxRePassword.BackColor = SystemColors.Window;
              textBoxRePassword.Text = "";
              AppSettings.Instance.MyEncryptPasswordBinary = null;

              // self-executable file
              if (AppSettings.Instance.fSaveToExeout == true)
              {
            ProcessType = PROCESS_TYPE_ATC_EXE;
            AppSettings.Instance.EncryptionFileType = FILE_TYPE_ATC_EXE;
              }

              // 明示的な暗号処理、または復号処理
              // Explicit encryption or decryption?
              if (AppSettings.Instance.ProcTypeWithoutAsk > 0)
              {
            if (AppSettings.Instance.ProcTypeWithoutAsk == 1) // Encryption
            {
              panelStartPage.Visible = false;
              panelEncrypt.Visible = true;        // Encrypt
              textBoxPassword.Focus();            // Text box is focused
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = false;
              panelProgressState.Visible = false;

            }
            else if(AppSettings.Instance.ProcTypeWithoutAsk == 2) // Decryption
            {
              panelStartPage.Visible = false;
              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = true;        // Decrypt
              textBoxDecryptPassword.Focus();     // Text box is focused
              panelProgressState.Visible = false;
            }

              }
              // 内容にかかわらず暗号化か復号かを問い合わせる
              // Ask to encrypt or decrypt regardless of contents.
              else if (AppSettings.Instance.FileList.Count() > 0 && AppSettings.Instance.fAskEncDecode == true)
              {
            Form4 frm4 = new Form4("AskEncryptOrDecrypt", "");
            frm4.ShowDialog();
            int ProcessNum = frm4.AskEncryptOrDecrypt;  // 1: Encryption, 2: Decryption, -1: Cancel
            frm4.Dispose();

            //-----------------------------------
            // Encryption
            //-----------------------------------
            if (ProcessNum == 1)
            {
              panelStartPage.Visible = false;
              panelEncrypt.Visible = true;        // Encrypt
              textBoxPassword.Focus();            // Text box is focused
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = false;
              panelProgressState.Visible = false;
            }
            //-----------------------------------
            // Decryption
            //-----------------------------------
            else if (ProcessNum == 2)
            {
              panelStartPage.Visible = false;
              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = true;        // Decrypt
              textBoxDecryptPassword.Focus();     // Text box is focused
              panelProgressState.Visible = false;
            }
            //-----------------------------------
            // Cancel
            //-----------------------------------
            else
            {
              this.BackColor = Color.White;
              return;
            }

              }
              else
              {
            //----------------------------------------------------------------------
            // 問い合わせず自動判別する
            // Auto detect without asking user

            // File type
            // private const int FILE_TYPE_ERROR        = -1;
            // private const int FILE_TYPE_NONE         = 0;
            // private const int FILE_TYPE_ATC          = 1;
            // private const int FILE_TYPE_ATC_EXE      = 2;
            // private const int FILE_TYPE_PASSWORD_ZIP = 3;
            //
            // -----------------------------------
            //
            // Process Type
            // private const int PROCESS_TYPE_ERROR        = -1;
            // private const int PROCESS_TYPE_NONE         = 0;
            // private const int PROCESS_TYPE_ATC          = 1;
            // private const int PROCESS_TYPE_ATC_EXE      = 2;
            // private const int PROCESS_TYPE_PASSWORD_ZIP = 3;
            // private const int PROCESS_TYPE_DECRYPTION   = 4;

            ProcessType = AppSettings.Instance.EncryptionSameFileTypeBefore;

            if (AppSettings.Instance.EncryptionSameFileTypeAlways > 0)
            {
              ProcessType = AppSettings.Instance.EncryptionSameFileTypeAlways;
            }

            // Specified file type
            if (ProcessType > 0)
            {
              // Detect file type
              int AtcProcessType = AppSettings.Instance.DetectFileType();

              if (AtcProcessType == PROCESS_TYPE_DECRYPTION)
              {
            ProcessType = AtcProcessType;
              }
            }
            else
            {
              // Detect file type
              ProcessType = AppSettings.Instance.DetectFileType();
            }

            if (AppSettings.Instance.FileList.Count() > 0)
            {
              //----------------------------------------------------------------------
              // Encryption
              if (ProcessType == PROCESS_TYPE_NONE || ProcessType == PROCESS_TYPE_ATC || ProcessType == PROCESS_TYPE_ATC_EXE)
              {
            panelStartPage.Visible = false;
            panelEncrypt.Visible = true;         // Encrypt
            panelEncryptConfirm.Visible = false;
            panelDecrypt.Visible = false;
            panelProgressState.Visible = false;

            /*
            if (ProcessType == FILE_TYPE_ATC_EXE) // Executable
            {
              pictureBoxEncryption.Image = pictureBoxExeOn.Image;
            }
            else
            {
              pictureBoxEncryption.Image = pictureBoxAtcOn.Image;
            }
            */

            this.Activate();              // MainForm is Activated
            textBoxPassword.Focus();      // Text box is focused
              }
              //----------------------------------------------------------------------
              // Decryption
              else if (ProcessType == PROCESS_TYPE_DECRYPTION)
              {
            panelStartPage.Visible = false;
            panelEncrypt.Visible = false;
            panelEncryptConfirm.Visible = false;
            panelDecrypt.Visible = true;
            panelProgressState.Visible = false;
            textBoxDecryptPassword.Focus();     // Text box is focused
            this.Activate();                    // MainForm is Activated
              }
              //----------------------------------------------------------------------
              // Password ZIP
              else if (ProcessType == FILE_TYPE_PASSWORD_ZIP)
              {
            panelStartPage.Visible = false;
            panelEncrypt.Visible = false;
            panelEncryptConfirm.Visible = false;
            panelDecrypt.Visible = true;            // Decrypt
            panelProgressState.Visible = false;

            pictureBoxEncryption.Image = pictureBoxZipOn.Image;

            this.Activate();                     // MainForm is Activated
            textBoxPassword.Focus();             // Text box is focused
              }
              //----------------------------------------------------------------------
              else
              {
            panelStartPage.Visible = true;       // Main Window
            panelEncrypt.Visible = false;
            panelEncryptConfirm.Visible = false;
            panelDecrypt.Visible = false;
            panelProgressState.Visible = false;
              }

              this.BackColor = Color.White;
            }

              }

              //----------------------------------------------------------------------
              // コマンドラインオプションからのパスワードが優先される
              // The password of command line option is still more priority.
              if (AppSettings.Instance.EncryptPasswordStringFromCommandLine != null ||
              AppSettings.Instance.DecryptPasswordStringFromCommandLine != null)
              {
            if (panelEncrypt.Visible == true)
            {
              // Password
              textBoxPassword.Text = AppSettings.Instance.EncryptPasswordStringFromCommandLine;
              textBoxRePassword.Text = AppSettings.Instance.EncryptPasswordStringFromCommandLine;

              // コマンドラインオプションからのパスワード:
              // The password of command line option:
              labelPassword.Text = Resources.labelPasswordOfCommandLineOption;
              labelInputPasswordAgain.Text = Resources.labelPasswordOfCommandLineOption;

              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = true;

              buttonEncryptStart.Focus();

              // 確認せず即座に実行
              // Run immediately without confirming
              if (AppSettings.Instance.fMemPasswordExe == true)
              {
            buttonEncryptStart.PerformClick();
              }
            }
            else if (panelDecrypt.Visible == true)
            {
              // Password
              textBoxDecryptPassword.Text = AppSettings.Instance.DecryptPasswordStringFromCommandLine;

              // コマンドラインオプションからのパスワード:
              // The password of command line option:
              labelDecryptionPassword.Text = Resources.labelPasswordOfCommandLineOption;

              buttonDecryptStart.Focus();

              // 確認せず即座に実行
              // Run immediately without confirming
              if (AppSettings.Instance.fMemPasswordExe == true)
              {
            buttonDecryptStart.PerformClick();
              }
            }
              }
              //-----------------------------------
              // 記憶パスワード(パスワードファイルより優先される)
              // Memorized password is priority than the saved password file
              else if (AppSettings.Instance.fMyEncryptPasswordKeep == true ||
                AppSettings.Instance.fMyDecryptPasswordKeep == true)
              {

            if (panelEncrypt.Visible == true)
            {
              // Password
              textBoxPassword.Text = AppSettings.Instance.MyEncryptPasswordString;
              textBoxRePassword.Text = AppSettings.Instance.MyEncryptPasswordString;

              // 記憶パスワード:
              // The memorized password:
              labelPassword.Text = Resources.labelPasswordMemorized;
              labelInputPasswordAgain.Text = Resources.labelPasswordMemorized;

              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = true;

              buttonEncryptStart.Focus();

              // 確認せず即座に実行
              // Run immediately without confirming
              if (AppSettings.Instance.fMyEncryptPasswordKeep == true && AppSettings.Instance.fMemPasswordExe == true)
              {
            buttonEncryptStart.PerformClick();
              }
            }
            else if (panelDecrypt.Visible == true)
            {
              // Password
              textBoxDecryptPassword.Text = AppSettings.Instance.MyDecryptPasswordString;

              // 記憶パスワード:
              // The memorized password:
              labelDecryptionPassword.Text = Resources.labelPasswordMemorized;

              buttonDecryptStart.Focus();

              // 確認せず即座に実行
              // Run immediately without confirming
              if (AppSettings.Instance.fMyDecryptPasswordKeep && AppSettings.Instance.fMemPasswordExe == true)
              {
            buttonDecryptStart.PerformClick();
              }
            }

              }
              //-----------------------------------
              // パスワードファイル
              // Password file
              else
              {
            //----------------------------------------------------------------------
            // Decryption
            if (AppSettings.Instance.fCheckPassFileDecrypt == true && panelDecrypt.Visible == true)
            {
              if (File.Exists(AppSettings.Instance.PassFilePath) == true)
              {
            AppSettings.Instance.MyDecryptPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.PassFilePathDecrypt);
            textBoxDecryptPassword.Text = AppSettings.BytesToHexString(AppSettings.Instance.MyDecryptPasswordBinary);

            textBoxDecryptPassword.Enabled = false;
            textBoxDecryptPassword.BackColor = SystemColors.ButtonFace;

            // パスワードファイル:
            // The Password file:
            labelPassword.Text = Resources.labelPasswordFile;
            labelInputPasswordAgain.Text = Resources.labelPasswordFile;

            panelStartPage.Visible = false;
            panelEncrypt.Visible = false;
            panelEncryptConfirm.Visible = false;
            panelDecrypt.Visible = true;
            panelProgressState.Visible = false;

            buttonDecryptStart.Focus();

            if ( AppSettings.Instance.fPasswordFileExe == true)
            {
              buttonDecryptStart.PerformClick();
            }

              }
              else
              {
            if (AppSettings.Instance.fNoErrMsgOnPassFile == false)
            {
              // 注意
              // 動作設定で指定されたパスワードファイルが見つかりません。
              // [FilePath]
              //
              // Alert
              // Password is not found that specified in setting panel.
              // [FilePath]
              DialogResult ret = MessageBox.Show(
                new Form { TopMost = true },
                Resources.DialogMessagePasswordFileNotFound + Environment.NewLine + AppSettings.Instance.PassFilePathDecrypt,
              Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return;
              }
            }
            //----------------------------------------------------------------------
            // Encryption
            else if (AppSettings.Instance.fCheckPassFile == true && panelEncrypt.Visible == true)
            {
              if (File.Exists(AppSettings.Instance.PassFilePath) == true)
              {
            AppSettings.Instance.MyDecryptPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.PassFilePath);
            textBoxPassword.Text = AppSettings.BytesToHexString(AppSettings.Instance.MyDecryptPasswordBinary);
            textBoxRePassword.Text = textBoxPassword.Text;

            // パスワードファイル:
            // The Password file:
            labelPassword.Text = Resources.labelPasswordFile;
            labelInputPasswordAgain.Text = Resources.labelPasswordFile;

            textBoxPassword.Enabled = false;
            textBoxPassword.BackColor = SystemColors.ButtonFace;
            textBoxRePassword.Enabled = false;
            textBoxRePassword.BackColor = SystemColors.ButtonFace;

            panelStartPage.Visible = false;
            panelEncrypt.Visible = false;
            panelEncryptConfirm.Visible = true;
            panelDecrypt.Visible = false;
            panelProgressState.Visible = false;

            buttonEncryptStart.Focus();

            if (AppSettings.Instance.fPasswordFileExe == true)
            {
              buttonEncryptStart.PerformClick();
            }

              }
              else
              {
            if (AppSettings.Instance.fNoErrMsgOnPassFile == false)
            {
              // 注意
              // 動作設定で指定されたパスワードファイルが見つかりません。
              // [FilePath]
              //
              // Alert
              // Password is not found that specified in setting panel.
              // [FilePath]
              DialogResult ret = MessageBox.Show(
                new Form { TopMost = true },
                Resources.DialogMessagePasswordFileNotFound + Environment.NewLine + AppSettings.Instance.PassFilePath,
              Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return;
              }
            }

              }
        }
예제 #4
0
        private void DialogMessageForOverWrite(int FileType, string FilePath)
        {
            if (decryption2 == null)
              {
            // Not confirm
            if (AppSettings.Instance.fDecryptConfirmOverwrite == false)
            {
              TempOverWriteOption = OVERWRITE_ALL;
              return;
            }

            if (TempOverWriteOption == OVERWRITE_ALL)
            {
              return;
            }
            else if(TempOverWriteOption == SKIP_ALL)
            {
              return;
            }

              }
              else
              {
            if (AppSettings.Instance.fDecryptConfirmOverwrite == false)
            {
              TempOverWriteOption = OVERWRITE_ALL;
              return;
            }

            if (TempOverWriteOption == OVERWRITE_ALL)
            {
              return;
            }
            else if (TempOverWriteOption == SKIP_ALL)
            {
              return;
            }
              }

              if (!bkg.IsBusy)
              {
            bkg.RunWorkerAsync();
            // Unblock the worker
            _busy.Set();
              }

              // Show dialog for confirming to orverwrite
              Form4 frm4;
              if (FileType == 0)
              {
            frm4 = new Form4("ComfirmToOverwriteDir", Resources.labelComfirmToOverwriteDir + Environment.NewLine + FilePath);
              }
              else
              {
            frm4 = new Form4("ComfirmToOverwriteFile", Resources.labelComfirmToOverwriteFile + Environment.NewLine + FilePath);
              }

              frm4.ShowDialog();

              TempOverWriteOption = frm4.OverWriteOption;

              frm4.Dispose();

              if (TempOverWriteOption == USER_CANCELED || TempOverWriteOption == SKIP_ALL)
              {
            if (bkg != null && bkg.IsBusy == true)
            {
              bkg.CancelAsync();
            }

            if (cts != null)
            {
              cts.Cancel();
            }
              }

              _busy.Reset();
        }