static int Main(string[] args) { //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); AppDomain appd = AppDomain.CurrentDomain; Process[] processes = Process.GetProcessesByName(Application.CompanyName); Enc.debug = debuglevel == 4; if (processes.Length > 1) { printf("已经有一个实例正在运行。"); Thread.Sleep(1000); Environment.Exit(1); } appd.ProcessExit += (s, e) => { printf("退出。"); Thread.Sleep(1000); }; Console.CancelKeyPress += delegate { printf("停止..."); screenshotThreadWorking = false; Environment.Exit(0); return; }; string fileDir = Environment.CurrentDirectory; printf("当前程序目录:" + fileDir); string temp = Environment.GetEnvironmentVariable("TEMP"); DirectoryInfo info = new DirectoryInfo(temp); string sysTempDir = info.FullName; string[] IniFileDirArr = Directory.GetFiles(fileDir, "*.ine"); string confFile = ""; if (IniFileDirArr.Length == 0) { // 沒有找到加密配置檔案,找明文配置檔案 IniFileDirArr = Directory.GetFiles(fileDir, "*.ini"); if (IniFileDirArr.Length == 0) { // 還是沒有找到 printf("找不到配置文件!", 3); return(-1); } else { confFile = IniFileDirArr[0]; } } else { // 找到加密的配置檔案,解密後加載 try { string txt = File.ReadAllText(IniFileDirArr[0]); txt = StringAES.Decrypt(txt, filePwd); tempini = sysTempDir + "\\" + randomString(64); File.WriteAllText(tempini, txt); confFile = IniFileDirArr[0]; IniFileDirArr[0] = tempini; } catch (Exception err) { printf("找不到配置文件!", 3); return(-1); } } string IniFileDir = IniFileDirArr[0]; printf("加载配置文件:" + confFile); INI ini = new INI(IniFileDir); if (!ini.ExistINIFile()) { printf("找不到配置文件!", 3); return(-1); } string[] opensslPaths = Enc.getOpensslPaths(); if (opensslPaths.Length == 0) { printf("找不到 OpenSSL !", 3); } else { Enc.opensslPath = opensslPaths[0]; printf("OpenSSL:" + opensslPaths[0]); } int screenW = Screen.PrimaryScreen.Bounds.Width; int screenH = Screen.PrimaryScreen.Bounds.Height; printf("主屏幕像素:" + screenW.ToString() + " × " + screenH.ToString()); prefix = ini.IniReadValue("User", "Prefix"); if (prefix.Length == 0) { prefix = "NyarukoEye"; } printf("文件前缀:" + prefix); tempdir = ini.IniReadValue("Work", "TempDir"); if (tempdir.Length == 0) { tempdir = sysTempDir + "\\" + prefix; } prefix += "_"; if (!Directory.Exists(tempdir)) { Directory.CreateDirectory(tempdir); } printf("临时文件夹:" + tempdir); imgType = ini.IniReadValue("File", "Type"); if (imgType.Length == 0) { imgType = "jpg"; } switch (imgType) { case "bmp": imgFormat = ImageFormat.Bmp; break; case "png": imgFormat = ImageFormat.Png; break; case "tif": imgFormat = ImageFormat.Tiff; break; case "gif": imgFormat = ImageFormat.Gif; break; default: imgFormat = ImageFormat.Jpeg; break; } printf("文件格式:" + imgType); encType = ini.IniReadValue("File", "EncType"); printf("加密文件格式:" + encType); keyType = ini.IniReadValue("File", "KeyType"); printf("对称密钥文件格式:" + keyType); encKeyType = ini.IniReadValue("File", "EncKeyType"); printf("被加密的对称密钥文件存储格式:" + encKeyType); publicKey = ini.IniReadValue("Encrypt", "PublicKey"); printf("公钥:" + publicKey); name = ini.IniReadValue("User", "Name"); if (name.Length == 0) { name = GetNumberAlpha(Environment.MachineName + Environment.UserDomainName + Environment.UserName) + "_"; } else { name = name + "_"; } symmetric = ini.IniReadValue("Encrypt", "Symmetric"); printf("对称加密算法:" + symmetric); string lengthI = ini.IniReadValue("Encrypt", "AESLength"); aesLength = int.Parse(lengthI); printf("对称加密长度:" + lengthI); printf("用户名:" + name); string sleepTimeSec = ini.IniReadValue("Work", "Sleep"); int sleepTimeSecInt = 60; if (sleepTimeSec.Length > 0) { sleepTimeSecInt = int.Parse(sleepTimeSec); sleepTime = sleepTimeSecInt * 1000; } uUsername = ini.IniReadValue("User", "Username"); printf("上载用户名:" + uUsername); uPassword = ini.IniReadValue("User", "Password"); printf("上载密码:<*>"); uURL = ini.IniReadValue("Network", "UploadURL"); printf("上载URL:" + uURL); printf("间隔时间(秒):" + sleepTimeSecInt.ToString()); sleepTimeSec = ini.IniReadValue("Work", "WorkSleep"); sleepTimeSecInt = 1; if (sleepTimeSec.Length > 0) { sleepTimeSecInt = int.Parse(sleepTimeSec); workSleepTime = sleepTimeSecInt * 1000; } printf("批量处理间隔时间(秒):" + sleepTimeSecInt.ToString()); ThreadStart screenshotRef = new ThreadStart(screenshotThreadRun); Thread screenshotThread = new Thread(screenshotRef); screenshotThread.Name = "screenshotThread" + (threadID++).ToString(); screenshotThread.Start(); printf("初始化完成。"); Application.Run(); return(0); }
private void openini(string iniPath = "") { if (iniPath.Length == 0) { iniPath = nowOpenINI; } INI ini = new INI(iniPath); string v = ini.IniReadValue("User", "Prefix"); if (v.Length > 0) { cPrefix.Text = v; } v = ini.IniReadValue("User", "Name"); if (v.Length > 0) { cName.Text = v; } v = ini.IniReadValue("File", "Type"); if (v.Length > 0) { cType.Text = v; } v = ini.IniReadValue("Work", "Sleep"); if (v.Length > 0) { int vi = int.Parse(v); if (vi >= cSleep.Minimum && vi <= cSleep.Maximum) { cSleep.Value = vi; } } v = ini.IniReadValue("Work", "TempDir"); if (v.Length > 0) { cTempDir.Text = v; } v = ini.IniReadValue("Work", "WorkSleep"); if (v.Length > 0) { int vi = int.Parse(v); if (vi >= cWorkSleep.Minimum && vi <= cWorkSleep.Maximum) { cWorkSleep.Value = vi; } } v = ini.IniReadValue("Encrypt", "Symmetric"); if (v.Length > 0) { cSymmetric.Text = v; } v = ini.IniReadValue("Encrypt", "AESLength"); if (v.Length > 0) { cAESLength.Text = v; } v = ini.IniReadValue("Encrypt", "PublicKey"); if (v.Length > 0) { cPublicKey.Text = v; } v = ini.IniReadValue("File", "KeyType"); if (v.Length > 0) { cKeyType.Text = v; } v = ini.IniReadValue("File", "EncType"); if (v.Length > 0) { cEncType.Text = v; } v = ini.IniReadValue("File", "EncKeyType"); if (v.Length > 0) { cEncKeyType.Text = v; } v = ini.IniReadValue("Network", "UploadURL"); if (v.Length > 0) { cUploadURL.Text = v; } v = ini.IniReadValue("User", "Username"); if (v.Length > 0) { cUsername.Text = v; } v = ini.IniReadValue("User", "Password"); if (v.Length > 0) { cPassword.Text = v; } }