Пример #1
0
 private void toolStripMenuItem1_Click(object sender, EventArgs e)
 {
     MessageBox.Show("> 读取非明文配置文件\n- 保存明文配置文件\n- 读入明文配置文件", "接下来的操作", MessageBoxButtons.OK, MessageBoxIcon.Information);
     openFileDialog1.FileName = "";
     openFileDialog1.Filter   = "非明文配置文件|*.ine|所有文件|*.*";
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         MessageBox.Show("+ 读取非明文配置文件\n> 保存明文配置文件\n- 读入明文配置文件", "接下来的操作", MessageBoxButtons.OK, MessageBoxIcon.Information);
         saveFileDialog1.FileName = "";
         saveFileDialog1.Filter   = "INI 配置文件|*.ini|所有文件|*.*";
         if (saveFileDialog1.ShowDialog() == DialogResult.OK)
         {
             nowOpenINI = "";
             try
             {
                 string txt = File.ReadAllText(openFileDialog1.FileName);
                 txt = StringAES.Decrypt(txt, cConfPwd.Text);
                 File.WriteAllText(saveFileDialog1.FileName, txt);
                 nowOpenINI = saveFileDialog1.FileName;
                 Text       = "配置编辑器 - " + nowOpenINI;
                 openini();
                 保存INI配置文件ToolStripMenuItem.Enabled = true;
             }
             catch (Exception err)
             {
                 MessageBox.Show(err.Message, "导入失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Пример #2
0
        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);
        }