コード例 #1
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Task task = Task.Factory.StartNew(() =>
     {
         String dump = CreateDumpFile();
         if (dump != null && File.Exists(Application.StartupPath + "/Temp/" + dump))
         {
             String CopyFile = Application.StartupPath + "/Temp/" + Path.GetFileNameWithoutExtension(CurrentFile) + ".dump";
             File.Copy(Application.StartupPath + "/Temp/" + dump, CopyFile, true);
             SetState("Assembling Dat File");
             Chronicle chronicle = (Chronicle)Convert.ToInt32(Properties.Settings.Default.DefaultChronicle);
             L2ASM asm           = new L2ASM();
             asm.AttachFile(CopyFile);
             string assembledFile = asm.Encrypt(chronicle);
             if (assembledFile != null && File.Exists(assembledFile))
             {
                 SetState("Encoding Assembeled File..");
                 L2Encdec encdec = new L2Encdec();
                 encdec.AttachFile(assembledFile);
                 string EncryptedFile = encdec.EncryptDat();
                 if (EncryptedFile != null && File.Exists(EncryptedFile))
                 {
                     String FinalFilePath = Application.StartupPath + "/Temp/" + CurrentFile;
                     File.Copy(EncryptedFile, FinalFilePath, true);
                     SetState("Asking for Overwrite Permission...");
                     DialogResult result = MessageBox.Show("Would you Like to Overwrite the Original File ?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                     if (result == DialogResult.Yes)
                     {
                         File.Copy(FinalFilePath, CurrentFilePath, true);
                         SetState("File has been overwritten for you.");
                         MessageBox.Show("File Successfully Updated");
                     }
                     else if (result == DialogResult.No)
                     {
                         SetState("Asking for Saving Location ...");
                         SaveFileDialog Save = new SaveFileDialog();
                         Save.FileName       = Path.GetFileNameWithoutExtension(CurrentFile);
                         Save.Title          = "Save to ...";
                         Save.Filter         = "Data Files (*.dat)|*.dat";
                         Save.DefaultExt     = "dat";
                         DialogResult res    = Save.ShowDialog();
                         if (res == DialogResult.OK)
                         {
                             File.Copy(FinalFilePath, Save.FileName, true);
                             SetState("File Saved Successfully");
                         }
                     }
                 }
             }
         }
     });
 }
コード例 #2
0
        public void LoadFile(String filePath)
        {
            L2Encdec encrypter = new L2Encdec();

            try
            {
                CurrentFilePath       = filePath;
                CurrentFile           = Path.GetFileName(filePath);
                currentFileLabel.Text = CurrentFile;
                encrypter.AttachFile(filePath);
                string decryptedFile = encrypter.Decrypt();
                if (decryptedFile != null)
                {
                    L2ASM asm = new L2ASM();
                    asm.AttachFile(decryptedFile);
                    String txtFile = asm.Decrypt((Chronicle)chronicleCombo.SelectedIndex);
                    if (txtFile != null)
                    {
                        ParseTextFile(txtFile);
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }