private void OptionWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //这里为窗口正在关闭时的回调函数,在这里用xml序列化方式写入setting.xml
            XMLSaveAndRead xmlHandle = new XMLSaveAndRead();

            //存储信息
            List <Settings> info = new List <Settings>();

            info.Add(this.settings);
            //将info的类型List<Test>和自身info传入
            string xmlInfo = xmlHandle.SerializeObject <List <Settings> >(info);
            string xmlPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            xmlPath += "settings.xml";
            xmlHandle.CreateXML(xmlPath, xmlInfo);
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            /*
             * 右键快捷加密解密部分
             */
            var args = Environment.GetCommandLineArgs();

            if (args.Length > 2)
            {
                string originPath = args[2];                    //获取加密文件路径

                FileScheme fileScheme = new FileScheme();

                if (args[1] == "encrypt")                       //加密文件
                {
                    fileScheme.File2Bytes(originPath, originPath += ".cb");
                }
                else if (args[1] == "decrypt" && originPath.Contains(".cb"))                     //解密文件,且检查是否为加密过的文件
                {
                    int index = originPath.IndexOf(".cb");
                    fileScheme.Bytes2File(originPath, originPath.Remove(index, 3));
                }
            }

            /*创建或读入设置文件部分*/
            string xmlPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            xmlPath += "settings.xml";
            if (!File.Exists(xmlPath))
            {
                XMLSaveAndRead xmlHandle = new XMLSaveAndRead();

                //存储信息
                List <Settings> info     = new List <Settings>();
                Settings        settings = new Settings(false, true, ("crtl", "E"), "3", SchemeType.Caesar, SchemeType.RailFence, SchemeType.Substitution);          //默认配置
                info.Add(settings);
                //将info的类型List<Test>和自身info传入
                string xmlInfo = xmlHandle.SerializeObject <List <Settings> >(info);
                xmlHandle.CreateXML(xmlPath, xmlInfo);
                CommonData.settings = settings;
            }
            else
            {
                XMLSaveAndRead  xmlHandle = new XMLSaveAndRead();
                string          doc       = xmlHandle.LoadXML(xmlPath);
                List <Settings> info1     = (List <Settings>)xmlHandle.DeserializeObject <List <Settings> >(doc);
                for (int i = 0; i < info1.Count; i++)
                {
                    CommonData.settings.isAutoStart    = info1[i].isAutoStart;
                    CommonData.settings.isUsingServer  = info1[i].isUsingServer;
                    CommonData.settings.shortCutKey    = info1[i].shortCutKey;
                    CommonData.settings.clipDefaultKey = info1[i].clipDefaultKey;
                    CommonData.settings.encryptType    = info1[i].encryptType;
                    CommonData.settings.decryptType    = info1[i].decryptType;
                    CommonData.settings.breakType      = info1[i].breakType;
                }
            }

            this.TaskListBox.ItemsSource = CommonData.Tasks;

            SqliteClient dbClient = new SqliteClient(CommonData.DbSource);

            dbClient.Open();
            var taskList = dbClient.QueryAllTask();

            foreach (var task in taskList)
            {
                CommonData.Tasks.Add(task);
            }
            dbClient.Close();

            //DebugWindow debugWindow = new DebugWindow();
            //debugWindow.Show();
        }