示例#1
0
        public void SaveFile(TabControl FileTabs, List <DataVariable> DataVar)
        {
            string RTBText = "";

            string FileName = FileTabs.SelectedTab.Text;

            if (FileName.Contains("NewPage"))
            {
                FileName = "";
                Stream         myStream;
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                int            FileNameL       = 0;
                saveFileDialog1.Filter           = "txt files (*.txt)|*.txt";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        // Code to write the stream goes here.
                        string change;
                        change = saveFileDialog1.FileName;
                        for (int loop = 0; loop < change.Length; loop++)
                        {
                            if (change[loop] == '\\')
                            {
                                FileNameL = 0;
                            }
                            else
                            {
                                FileNameL++;
                            }
                        }
                        for (int loop = change.Length - FileNameL; loop < change.Length; loop++)
                        {
                            FileName += change[loop];
                        }
                        FileTabs.SelectedTab.Text = FileName;
                        FileName = change;
                        myStream.Close();
                        //DataVar[FileTabs.SelectedIndex].FileSources = change;
                        DataVariable DatavarTemp = new DataVariable();
                        DatavarTemp.Tabs                = DataVar[FileTabs.SelectedIndex].Tabs;
                        DatavarTemp.Encrypted           = DataVar[FileTabs.SelectedIndex].Encrypted;
                        DatavarTemp.FileSources         = change;
                        DataVar[FileTabs.SelectedIndex] = DatavarTemp;
                    }
                }
            }
            if (!DataVar[FileTabs.SelectedIndex].Encrypted)
            {
                RTBText = Encrypt(DataVar[FileTabs.SelectedIndex].Tabs.Rtf);
            }
            BinaryRW write = new BinaryRW();

            write.writeBytes(Encryptedbytes, DataVar[FileTabs.SelectedIndex].FileSources);
            // Debug.WriteLine("Save Passed " + FileName);
        }
示例#2
0
        public string Decrypt(string _tmp)
        {
            string DecryptText = "";

            byte[] Key;
            Key = _32bit.GetBytes(Properties.Settings.Default.Password);
            BinaryRW Read = new BinaryRW();

            byte[] bytetostring;
            byte[] IV = _32bit.GetBytes("12700779");
            bytetostring = Convert.FromBase64String(_tmp);
            DecryptText  = _32bit.decrypt_function(bytetostring, Key, IV);
            //Debug.WriteLine("Decrypting Tab index: " + FileTabs.SelectedIndex.ToString() + " Name: " + Tabs[FileTabs.SelectedIndex].Name);
            return(DecryptText);
        }
示例#3
0
        public string[] OpenFile()
        {
            string[]       ArgVal          = new string[3];
            OpenSource     dlg             = new OpenSource();
            string         FileName        = "";
            int            FileNameL       = 0;
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            try
                            {
                                Source = openFileDialog1.FileName;
                                //FileSources.Add(Source);
                                string   DecryotedText;
                                string   GrabbedText;
                                byte[]   bytes;
                                BinaryRW Read = new BinaryRW();
                                bytes         = Read.ReadBytes(Source);
                                GrabbedText   = Convert.ToBase64String(bytes);
                                DecryotedText = Decrypt(GrabbedText);
                                for (int loop = 0; loop < Source.Length; loop++)
                                {
                                    if (Source[loop] == '\\')
                                    {
                                        FileNameL = 0;
                                    }
                                    else
                                    {
                                        FileNameL++;
                                    }
                                }
                                for (int loop = Source.Length - FileNameL; loop < Source.Length; loop++)
                                {
                                    FileName += Source[loop];
                                }
                                ArgVal[0] = FileName;
                                ArgVal[1] = DecryotedText;
                                ArgVal[2] = Source;
                                return(ArgVal);
                                // AddPage(FileName, DecryotedText);
                                //Debug.WriteLine("Open File Passed " + FileName);
                            }
                            catch
                            {
                                // Debug.WriteLine("Open File Failed " + FileName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            return(null);
        }