private void button1_Click(object sender, EventArgs e) { regConf conf = new regConf(); string sid = WindowsIdentity.GetCurrent().User.Value; cpRegFile rf = new cpRegFile("input.reg"); bool res = rf.importRegFile(); if (!res) { MessageBox.Show("error importing"); } cpContainers tmpcontainers = new cpContainers($@"{conf.getParam("baseKey", "")}\{sid}\{conf.getParam("cpKeys", "")}", $@"{appdatapath}\cpKey.list"); listBox1.Items.Clear(); List <string> toinstall = tmpcontainers.compareList(); if (toinstall.Count > 0) { foreach (string item in toinstall) { if (tmpcontainers.instCert(item)) { listBox1.Items.Add(item); } } } }
private void timer1_Tick(object sender, EventArgs e) { string inputpath = $@"{appdatapath}\input.reg"; bool res = false; regConf conf = new regConf(); string sid = WindowsIdentity.GetCurrent().User.Value; timer1.Stop(); if (File.Exists(inputpath)) { log.writeLog($"{inputpath} found.\r\n"); cpRegFile rf = new cpRegFile(inputpath); log.writeLog($"Trying to import {inputpath}\r\n"); try { res = rf.importRegFile(); if (res) { log.writeLog($"{inputpath} successfully imported.\r\n"); } else { log.writeLog($"Unknown error while importing {inputpath}!\r\n"); } } catch (Exception ex) { log.writeLog(FormatErrorStr($"Error while importing {inputpath}!\r\n Details:\r\n", ex)); } } cpContainers cont = new cpContainers($@"{conf.getParam("baseKey", "")}\{sid}\{conf.getParam("cpKeys", "")}", $@"{appdatapath}\cpKey.list"); try { List <string> toinstall = cont.compareList(); List <string> installed = new List <string>(); if (toinstall.Count > 0) { foreach (string item in toinstall) { try { log.writeLog($"Trying to install certificate from {item} container...\r\n"); if (cont.instCert(item)) { installed.Add(item); log.writeLog($"OK Certificate from {item} container installed successfully!\r\n"); } else { log.writeLog($"ERROR while installing certificate {item}! No certificate in key containers?\r\n"); log.writeLog($"Try to run {conf.getParam("pathCSPTest", "")} {item} for details.\r\n"); } } catch (Exception ex) { log.writeLog(FormatErrorStr($"ERROR while installing certificate {item}!\r\n Details:\r\n", ex)); } } if (installed.Count > 0) { try { File.WriteAllLines($@"{appdatapath}\lasttimeinstalled.txt", installed.ToArray()); } catch { // } notifyIcon1.BalloonTipTitle = "ЭЦП Установлены!"; notifyIcon1.BalloonTipText = $"Количество установленных ЭЦП: {installed.Count}\r\n Нажмите для просмотра списка."; notifyIcon1.ShowBalloonTip(900 * 1000); } } } catch (Exception ex) { log.writeLog(FormatErrorStr($"Error while comparing containers list!\r\n Details:\r\n", ex)); } timer1.Start(); }