示例#1
0
文件: IOUtils.cs 项目: swsk33/EZSetup
        /// <summary>
        /// 利用7z命令获取压缩文件解压后的大小
        /// </summary>
        /// <param name="filePath">压缩文件</param>
        /// <returns></returns>
        public static long Get7zOriginSize(string filePath)
        {
            string[] terminalResult = TerminalUtils.RunCommand("7z", "l \"" + filePath + "\"");
            string   sizeInfo       = terminalResult[0].Substring(terminalResult[0].LastIndexOf(":") + 3).Trim();

            sizeInfo = sizeInfo.Substring(0, sizeInfo.IndexOf(" "));
            return(long.Parse(sizeInfo));
        }
示例#2
0
        /// <summary>
        /// 运行setx命令设定环境变量
        /// </summary>
        /// <param name="varName">设定变量名</param>
        /// <param name="value">变量值</param>
        /// <param name="isSysVar">是否是系统变量</param>
        public static void RunSetx(string varName, string value, bool isSysVar)
        {
            List <string> args = new List <string>();

            if (isSysVar)
            {
                args.Add("/m");
            }
            args.Add(varName);
            value = FilePathUtils.RemovePathEndBackslash(value);
            args.Add(value);
            TerminalUtils.RunCommand("setx", args.ToArray());
        }
示例#3
0
文件: Program.cs 项目: swsk33/EZSetup
 /// <summary>
 /// 安装后执行
 /// </summary>
 public static void DoAfterInstall()
 {
     Environment.CurrentDirectory = ConfigUtils.GlobalConfigure.InstallPath;
     if (ConfigUtils.GlobalConfigure.OpenAfterSetup)
     {
         Process.Start(ConfigUtils.GlobalConfigure.InstallPath + "\\" + ConfigUtils.GlobalConfigure.MainEXE);
     }
     if (!ConfigUtils.GlobalConfigure.RunAfterSetup.Equals(""))
     {
         string totalCommand = ConfigUtils.GlobalConfigure.RunAfterSetup;
         if (totalCommand.Contains(" "))
         {
             string command = totalCommand.Substring(0, totalCommand.IndexOf(" "));
             string args    = totalCommand.Substring(totalCommand.IndexOf(" ") + 1);
             TerminalUtils.RunCommand(command, args);
         }
         else
         {
             Process.Start(totalCommand);
         }
     }
 }
示例#4
0
文件: MainGUI.cs 项目: swsk33/EZSetup
 private void done_Click(object sender, EventArgs e)
 {
     Hide();
     Environment.CurrentDirectory = pathValue.Text;
     if (ConfigUtils.GlobalConfigure.OpenAfterSetup && openNow.Checked)
     {
         Process.Start(ConfigUtils.GlobalConfigure.MainEXE);
     }
     if (!ConfigUtils.GlobalConfigure.RunAfterSetup.Equals(""))
     {
         if (ConfigUtils.GlobalConfigure.RunAfterSetup.Contains(" "))
         {
             string command = ConfigUtils.GlobalConfigure.RunAfterSetup.Substring(0, ConfigUtils.GlobalConfigure.RunAfterSetup.IndexOf(" "));
             string args    = ConfigUtils.GlobalConfigure.RunAfterSetup.Substring(ConfigUtils.GlobalConfigure.RunAfterSetup.IndexOf(" ") + 1);
             TerminalUtils.RunCommand(command, args);
         }
         else
         {
             Process.Start(ConfigUtils.GlobalConfigure.RunAfterSetup);
         }
     }
     Application.Exit();
 }
示例#5
0
        private void ok_Click(object sender, EventArgs e)
        {
            uninstalling.Visible = true;
            ok.Enabled           = false;
            cancel.Enabled       = false;
            Configure cfg = JsonConvert.DeserializeObject <Configure>(File.ReadAllText(WORK_PLACE + "\\cfg.ezcfg"));

            if (!cfg.RunBeforeUnSetup.Equals(""))
            {
                state.Text = "执行卸载前命令...";
                Application.DoEvents();
                Environment.CurrentDirectory = appPath;
                string totalCommand = cfg.RunBeforeUnSetup;
                if (totalCommand.Contains(" "))
                {
                    string command = totalCommand.Substring(0, totalCommand.IndexOf(" "));
                    string args    = totalCommand.Substring(totalCommand.IndexOf(" ") + 1);
                    TerminalUtils.RunCommand(command, args);
                }
                else
                {
                    Process.Start(totalCommand);
                }
            }
            if (cfg.GenerateShortcut)
            {
                state.Text = "移除快捷方式...";
                Application.DoEvents();
                try
                {
                    if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + cfg.Title))
                    {
                        Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + cfg.Title, true);
                    }
                    if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + cfg.Title + ".lnk"))
                    {
                        File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + cfg.Title + ".lnk");
                    }
                }
                catch
                {
                    //none
                }
            }
            if (cfg.AddBootOption)
            {
                state.Text = "移除开机启动项...";
                Application.DoEvents();
                RegUtils.OperateBootOption(cfg.Title, "", false);
            }
            state.Text = "移除程序信息注册表...";
            Application.DoEvents();
            RegUtils.OperateAppUninstallItem(new AppUninstallInfo(cfg.Title, ""), false);
            state.Text = "移除文件...";
            Application.DoEvents();
            string[] dirList  = Directory.GetDirectories(appPath);
            string[] fileList = Directory.GetFiles(appPath);
            foreach (string dir in dirList)
            {
                try
                {
                    Directory.Delete(dir, true);
                }
                catch
                {
                    //none
                }
            }
            foreach (string file in fileList)
            {
                if (!file.Equals(selfPath))
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch
                    {
                        //none
                    }
                }
            }
            File.WriteAllText(WORK_PLACE + "\\delete.vbs", "wscript.sleep 1000*1\r\nset f=createobject(\"Scripting.FileSystemObject\")\r\nf.DeleteFolder(\"" + appPath + "\"),true\r\nf.DeleteFolder(\"" + WORK_PLACE + "\"),true\r\ncall MsgBox(\"卸载成功!\", 64, \"完成\")", Encoding.GetEncoding("gbk"));
            Process.Start(WORK_PLACE + "\\delete.vbs");
            Application.Exit();
        }
示例#6
0
文件: IOUtils.cs 项目: swsk33/EZSetup
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="exePath">exe文件原位置</param>
        /// <param name="destPath">快捷方式目标位置</param>
        /// <param name="args">快捷方式运行参数</param>
        public static void CreateShortcut(string exePath, string destPath, string args)
        {
            string workingDirectory = exePath.Substring(0, exePath.LastIndexOf("\\"));

            TerminalUtils.RunCommand(ConfigUtils.WORK_PLACE + "\\shortcut.exe", TextUtils.SurroundByDoubleQuotes(exePath) + " " + TextUtils.SurroundByDoubleQuotes(destPath) + " " + TextUtils.SurroundByDoubleQuotes(workingDirectory) + " " + args);
        }
示例#7
0
        private void ok_Click(object sender, EventArgs e)
        {
            if (outputPathValue.Text.Equals(""))
            {
                MessageBox.Show("请设定输出路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (setIcon.Checked && !File.Exists(iconPath.Text))
            {
                MessageBox.Show("所选图标文件不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (templateList.SelectedIndex < 0)
            {
                MessageBox.Show("请选择安装包模板!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            prepareTip.Visible = true;
            ok.Enabled         = false;
            Application.DoEvents();
            string tmpDir = createTmpDir();

            Environment.SetEnvironmentVariable("Path", cscVersions[cscVersionBox.SelectedItem.ToString()] + ";" + Environment.GetEnvironmentVariable("Path"));
            TerminalUtils.RunCommand(refer7zPath, "x \"TemplatePack\\" + templateList.SelectedItem.ToString() + ".7z\" -o\"" + tmpDir + "\"");
            prepareTip.Visible = false;
            ok.Enabled         = true;
            Visible            = false;
            string[] runConfig = TerminalUtils.RunCommand(tmpDir + "\\ConfigModule.exe", "");
            if (runConfig[0].StartsWith("0"))
            {
                mainTabPanel.SelectedIndex = 0;
                Visible = true;
            }
            else
            {
                Visible = false;
                ProcessForm form = new ProcessForm();
                form.Show();
                Application.DoEvents();
                form.dir = outputPathValue.Text.Substring(0, outputPathValue.Text.LastIndexOf("\\"));
                string packedPath   = runConfig[0].Substring(0, runConfig[0].LastIndexOf("|"));
                string genUninstall = runConfig[0].Substring(runConfig[0].LastIndexOf("|") + 1);
                if (setIcon.Checked)
                {
                    File.Copy(iconPath.Text, tmpDir + "\\Resources\\icon.ico", true);
                }
                string compressLevelArg;
                switch (compressLevelValue.SelectedIndex)
                {
                case 0:
                    compressLevelArg = "-mx1";
                    break;

                case 1:
                    compressLevelArg = "-mx3";
                    break;

                case 2:
                    compressLevelArg = "-mx5";
                    break;

                case 3:
                    compressLevelArg = "-mx7";
                    break;

                default:
                    compressLevelArg = "-mx9";
                    break;
                }
                if (File.Exists(tmpDir + "\\Resources\\data.7z"))
                {
                    File.Delete(tmpDir + "\\Resources\\data.7z");
                }
                string   compressCommandArgs = "a -y -t7z " + compressLevelArg + " \"" + tmpDir + "\\Resources\\data.7z\" \"" + packedPath + "\\*\"";
                string[] compressData        = TerminalUtils.RunCommand(refer7zPath, compressCommandArgs);
                form.progressBar.Value = 75;
                Application.DoEvents();
                string[] genUnSetup = null;
                string[] addUnSetup = null;
                if (genUninstall.StartsWith("1") && !File.Exists(packedPath + "\\uninstall.exe"))
                {
                    genUnSetup = TerminalUtils.RunCommand(tmpDir + "\\build.bat", "u uninstall.exe");
                    addUnSetup = TerminalUtils.RunCommand(refer7zPath, "a -y " + "\"" + tmpDir + "\\Resources\\data.7z\" \"" + tmpDir + "\\uninstall.exe\"");
                }
                form.progressBar.Value = 90;
                Application.DoEvents();
                string[] buildInstallPack = TerminalUtils.RunCommand(tmpDir + "\\build.bat", "i \"" + outputPathValue.Text + "\"");
                form.progressBar.Value = 100;
                Application.DoEvents();
                if (File.Exists(outputPathValue.Text))
                {
                    form.processingTip.Text      = "构建完成!";
                    form.processingTip.ForeColor = Color.Green;
                    form.close.Enabled           = true;
                    form.openDir.Enabled         = true;
                }
                else
                {
                    form.processingTip.Text      = "构建失败!";
                    form.processingTip.ForeColor = Color.Red;
                    form.close.Enabled           = true;
                    string stdOut = "压缩数据:\r\n" + compressData[0] + "\r\n";
                    string stdErr = "压缩数据:\r\n" + compressData[1] + "\r\n";
                    if (genUnSetup != null)
                    {
                        stdOut = stdOut + "构建卸载程序:\r\n" + genUnSetup[0] + "\r\n添加卸载程序:\r\n" + addUnSetup[0] + "\r\n";
                        stdErr = stdErr + "构建卸载程序:\r\n" + genUnSetup[1] + "\r\n添加卸载程序:\r\n" + addUnSetup[1] + "\r\n";
                    }
                    stdOut = stdOut + "构建安装程序:\r\n" + buildInstallPack[0];
                    stdErr = stdErr + "构建安装程序:\r\n" + buildInstallPack[1];
                    new FailedInfo().InitContent(stdOut, stdErr);
                }
            }
            Directory.Delete(tmpDir, true);
        }
示例#8
0
 private void downSDK_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     TerminalUtils.RunCommand("cmd", "/c start https://dotnet.microsoft.com/download/dotnet-framework/thank-you/net48-developer-pack-offline-installer");
 }
示例#9
0
 private void referNewSoftJson_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     TerminalUtils.RunCommand("cmd", "/c start https://www.newtonsoft.com/json");
 }
示例#10
0
 private void refer7z_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     TerminalUtils.RunCommand("cmd", "/c start https://www.7-zip.org/");
 }