コード例 #1
0
ファイル: Form1.cs プロジェクト: di110n/CPKeysManager
        private void mbExport_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string expath = saveFileDialog1.FileName;

            if (CLBKeys.CheckedItems.Count <= 0)
            {
                tbLog.AppendText($"{CPKMStrings.txtErrNoKeysToAction}\r\n");
                return;
            }

            this.Enabled = false;

            cpKeyReg      cpKey = new cpKeyReg(null, null);
            List <string> data  = new List <string>();

            data.Add("Windows Registry Editor Version 5.00");
            data.Add("");
            data.Add($@"[HKEY_LOCAL_MACHINE\{CPKMConfig.baseCPKey}\{usersList[LBUsersList.SelectedItem.ToString()]}\{CPKMConfig.baseCPKKey}]");
            data.Add("");
            try
            {
                foreach (var ikey in CLBKeys.CheckedItems)
                {
                    cpKey.keyname = ikey.ToString();
                    cpKey.sid     = usersList[LBUsersList.SelectedItem.ToString()];
                    data.AddRange(cpKey.getKey().ToList());
                }
            }
            catch (Exception ex)
            {
                tbLog.AppendText($"Ошибка экспорта контейнера! Детали:\r\n{ex.Source}\r\n{ex.TargetSite}\r\n{ex.Message}\r\n");
            }

            //////////

            try
            {
                File.WriteAllLines(expath, data.ToArray(), Encoding.Unicode);
            }
            catch
            {
                tbLog.AppendText($"Ошибка записи {expath}");
            }

            this.Enabled = true;

            tbLog.AppendText($"{CPKMStrings.txtDone}\r\n");
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: di110n/CPKeysManager
        private void mbCopy_Click(object sender, EventArgs e)
        {
            if (CLBKeys.CheckedItems.Count <= 0)
            {
                tbLog.AppendText($"{CPKMStrings.txtErrNoKeysToAction}\r\n");
                return;
            }

            Form frmSelectUsers = new SelectUsers(LBUsersList.Items, LBUsersList.SelectedIndex, CPKMStrings.txtMsgSelectUserToCopyKeys);

            frmSelectUsers.StartPosition        = FormStartPosition.CenterParent;
            cpkmDataExchange.cpkmvSelectedUsers = null;
            frmSelectUsers.ShowDialog(this);

            if (cpkmDataExchange.cpkmvSelectedUsers == null)
            {
                tbLog.AppendText($"{CPKMStrings.txtErrNoUsersToCopyKeys}\r\n");
                return;
            }

            this.Enabled = false;

            cpKeyReg      cpKey = new cpKeyReg(null, null);
            List <string> data  = new List <string>();

            data.Add("Windows Registry Editor Version 5.00");
            data.Add("");
            data.Add($@"[HKEY_LOCAL_MACHINE\{CPKMConfig.baseCPKey}\{usersList[LBUsersList.SelectedItem.ToString()]}\{CPKMConfig.baseCPKKey}]");
            data.Add("");
            try
            {
                foreach (var ikey in CLBKeys.CheckedItems)
                {
                    cpKey.keyname = ikey.ToString();
                    cpKey.sid     = usersList[LBUsersList.SelectedItem.ToString()];
                    data.AddRange(cpKey.getKey().ToList());
                }
            }
            catch (Exception ex)
            {
                tbLog.AppendText($"Ошибка экспорта контейнера! Детали:\r\n{ex.Source}\r\n{ex.TargetSite}\r\n{ex.Message}\r\n");
            }
            try
            {
                File.WriteAllLines("tmpinput.reg", data.ToArray(), Encoding.Unicode);
            }
            catch
            {
                tbLog.AppendText("Ошибка записи tmpinput.reg");
            }

            if (File.Exists("tmpinput.reg"))
            {
                try
                {
                    foreach (var item in cpkmDataExchange.cpkmvSelectedUsers)
                    {
                        File.Copy("tmpinput.reg", $@"{uPathList[item.ToString()]}\input.reg");
                        if (cpkmDataExchange.cpkmvForceReinstallCerts)
                        {
                            File.Delete($@"{uPathList[item.ToString()]}\cpKey.list");
                        }
                    }
                    File.Delete("tmpinput.reg");
                }
                catch (Exception ex)
                {
                    tbLog.AppendText($"Ошибка копирования input.reg! Детали:\r\n{ex.Source}\r\n{ex.TargetSite}\r\n{ex.Message}\r\n");
                }
            }
            cpkmDataExchange.cpkmvSelectedUsers       = null;
            cpkmDataExchange.cpkmvForceReinstallCerts = false;
            this.Enabled = true;

            tbLog.AppendText($"{CPKMStrings.txtDone}\r\n");
        }