コード例 #1
0
ファイル: AppRemoteTerminal.cs プロジェクト: sergey-msu/azos
        public virtual string Execute(string command)
        {
            m_WhenInteracted = App.TimeSource.UTCNow;

            if (command == null)
            {
                return(string.Empty);
            }

            command = command.Trim();

            if (command.IsNullOrWhiteSpace())
            {
                return(string.Empty);
            }

            if (!command.EndsWith("}") && command.Contains(HELP_ARGS))
            {
                return(getHelp(command.Replace(HELP_ARGS, "").Trim()));
            }

            if (!command.EndsWith("}"))
            {
                command += "{}";
            }

            var cmd    = TerminalUtils.ParseCommand(command, m_Vars);
            var result = new MemoryConfiguration();

            result.EnvironmentVarResolver = cmd.EnvironmentVarResolver;
            m_ScriptRunner.Execute(cmd, result);

            return(DoExecute(result.Root));
        }
コード例 #2
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));
        }
コード例 #3
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());
        }
コード例 #4
0
 public static MyOnScreenApplication InitSingleScreenApplication(
     IMyGridTerminalSystem MyGridTerminalSystem, String textPanelName, int surfaceIndex,
     int resX, int resY, bool mirrorX,
     int nComputeIterations = 1, int nDrawIterations = 1
     )
 {
     return(new MyOnScreenApplication(nComputeIterations, nDrawIterations)
            .WithCanvas(
                new MyCanvas(resX, resY)
                )
            .OnScreen(
                new MyScreen(
                    TerminalUtils.FindTextSurface(MyGridTerminalSystem, textPanelName, surfaceIndex),
                    SCREEN_PIXEL_VALUE_ON, SCREEN_PIXEL_VALUE_OFF,
                    mirrorX
                    )
                ));
 }
コード例 #5
0
        public static void Main(string[] args)
        {
            try
            {
                run(args);
            }
            catch (Exception error)
            {
                ConsoleUtils.Error(error.ToMessageWithType());
                ConsoleUtils.Info("Exception details:");
                Console.WriteLine(error.ToString());

                if (error is RemoteException)
                {
                    TerminalUtils.ShowRemoteException((RemoteException)error);
                }

                Environment.ExitCode = -1;
            }
        }
コード例 #6
0
/**
 * This is called from the 5th loop
 * It should be used for initializing the application.
 *      > adding pages
 *      > adding components to the pages
 *      > linking logic and animations
 */
                             private void InitApplication()
                             {
                                 // Set up the target screen
                                 TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, PIXEL_SIZE);

                                 OnScreenApplication = UiFrameworkUtils.InitSingleScreenApplication(
                                     GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, // The target panel
                                     RES_X, RES_Y,                                         // The target resolution
                                     MIRROR_X_AXIS,                                        // Rendering option
                                     N_COMPUTE_FRAMES,                                     // The number of compute iterations
                                     N_RENDER_FRAMES                                       // The number of draw iterations
                                     )
                                                       .WithDefaultPostPage((MyOnScreenApplication app) => {
                // The POST page should disappear after 100 frames
                currFrame++;
                return(currFrame >= POST_SCREEN_DURATION);
            });

                                 // Add more pages
                                 InitPages(OnScreenApplication);
                             }
コード例 #7
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);
         }
     }
 }
コード例 #8
0
/**
 * This is called from the 5th loop
 * It should be used for initializing the application.
 *      > adding pages
 *      > adding components to the pages
 *      > linking logic and animations
 */
                             private void InitApplication()
                             {
                                 // Set up the target screen
                                 TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, PIXEL_SIZE);

                                 // Initialize the application
                                 OnScreenApplication = UiFrameworkUtils.InitSingleScreenApplication(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, RES_X, RES_Y, false)
                                                       .WithDefaultPostPage((MyOnScreenApplication app) => {
                // The POST page should disappear after the configured number of frames
                currFrame++;
                return(currFrame >= POST_SCREEN_DURATION);
            });

                                 // Create the main page and add it to the application
                                 MyPage MainPage = InitMainPage();

                                 if (INVERT_COLORS)
                                 {
                                     MainPage.WithInvertedColors();
                                 }
                                 OnScreenApplication.AddPage(MainPage);
                             }
コード例 #9
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();
 }
コード例 #10
0
                                 public MyChaseLightController(
                                     IMyGridTerminalSystem GridTerminalSystem,
                                     string textPanelName,
                                     bool mirrored,
                                     int operatingMode,
                                     int movementSpeed,
                                     MySprite[] ChaseLightShapeFrames
                                     )
                                 {
                                     // Sanity check
                                     if (textPanelName == null || textPanelName.Length == 0)
                                     {
                                         throw new ArgumentException("The name of the text panel must not be at least one character long");
                                     }

                                     if (ChaseLightShapeFrames == null || ChaseLightShapeFrames.Length == 0)
                                     {
                                         throw new ArgumentException("The ChaseLightShapeFrames array must have at least one element");
                                     }

                                     if (operatingMode < OP_MODE_LEFT_TO_RIGHT || operatingMode > OP_MODE_BOUNCE_START_FROM_RIGHT)
                                     {
                                         throw new ArgumentException("The operating mode must have one of the following values: OP_MODE_LEFT_TO_RIGHT, OP_MODE_RIGHT_TO_LEFT, OP_MODE_BOUNCE_START_FROM_LEFT, OP_MODE_BOUNCE_START_FROM_RIGHT");
                                     }

                                     if (movementSpeed < 1 || movementSpeed > 10)
                                     {
                                         throw new ArgumentException("The movement speed must be between 1 and 10");
                                     }

                                     // Set up the text panel
                                     TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, textPanelName, 0, FONT_SIZE);

                                     // Initialize the application
                                     OnScreenApplication
                                         = UiFrameworkUtils.InitSingleScreenApplication(
                                               GridTerminalSystem, textPanelName, 0, // Reference to the target text panel
                                               RES_X, RES_Y,                         // The target display resolution
                                               mirrored                              // The screen image might have to be mirrored
                                               );

                                     // Create the main page and add it to the application
                                     MyPage MainPage = new MyPage();

                                     OnScreenApplication.AddPage(MainPage);

                                     // Create the ChaseLightShape with only one state, named "Default",
                                     // having the referenced frames array as its animation
                                     ChaseLightShape = new MyStatefulAnimatedSprite(0, 0)
                                                       .WithState("Default", new MyStatefulAnimatedSpriteState(ChaseLightShapeFrames));

                                     // Add the ChaseLightShape to the main page
                                     MainPage.AddChild(ChaseLightShape);

                                     // Set the movement vector
                                     if (operatingMode == OP_MODE_RIGHT_TO_LEFT || operatingMode == OP_MODE_BOUNCE_START_FROM_RIGHT)
                                     {
                                         movementVector = -movementSpeed;
                                     }
                                     else
                                     {
                                         movementVector = movementSpeed;
                                     }

                                     // Set the client cycle method to the chase light shape according to the referenced operating mode
                                     ChaseLightShape.WithClientCycleMethod((MyOnScreenObject Obj, int currFrameIndex) => {
                    // Center vertically (each frame might have a different height,
                    // so this is required to run on every frame)
                    Obj.y = (RES_Y - Obj.GetHeight()) / 2;

                    // Move
                    Obj.x += movementVector;

                    // Apply the proper action for when the object goes off-screen,
                    // according to the set operating mode
                    if (operatingMode == OP_MODE_RIGHT_TO_LEFT)
                    {
                        // If it's right to left, then the objects exits through the
                        // left side and enters through the right side of the screen.
                        if (Obj.x < 0)
                        {
                            Obj.x = RES_X - 1 - Obj.GetWidth();
                        }
                    }
                    else if (
                        operatingMode == OP_MODE_BOUNCE_START_FROM_LEFT ||
                        operatingMode == OP_MODE_BOUNCE_START_FROM_RIGHT
                        )
                    {
                        // If it's bouncing, then the object's vector has to be switched
                        // whenever it reches one side or the other.
                        if (Obj.x < 0 || Obj.x + Obj.GetWidth() > RES_X - 1)
                        {
                            movementVector = -movementVector;
                        }
                    }
                    else
                    {
                        // The default is OP_MODE_LEFT_TO_RIGHT.
                        // In this case, the objects exits the screen through the right side
                        // and enters through the left side.
                        if (Obj.x + Obj.GetWidth() > RES_X - 1)
                        {
                            Obj.x = 0;
                        }
                    }
                });
                                 }
コード例 #11
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();
        }
コード例 #12
0
        static void run(string[] args)
        {
            using (var app = new AzosApplication(args, null))
            {
                var silent = app.CommandArgs["s", "silent"].Exists;
                if (!silent)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Welcome.txt"));

                    ConsoleUtils.Info("Build information:");
                    Console.WriteLine(" Azos:     " + BuildInformation.ForFramework);
                    Console.WriteLine(" Tool:     " + new BuildInformation(typeof(ascon.ProgramBody).Assembly));
                }

                if (app.CommandArgs["?", "h", "help"].Exists)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Help.txt"));
                    return;
                }


                var cred = app.CommandArgs["c", "cred"];
                var user = cred.AttrByName("id").Value;
                var pwd  = cred.AttrByName("pwd").Value;

                if (user.IsNullOrWhiteSpace())
                {
                    if (!silent)
                    {
                        Console.Write("User ID: ");
                    }
                    user = Console.ReadLine();
                }
                else
                if (!silent)
                {
                    ConsoleUtils.Info("User ID: " + user);
                }

                if (pwd.IsNullOrWhiteSpace())
                {
                    if (!silent)
                    {
                        Console.Write("Password: "******"Password: <supplied>");
                }


                var node = app.CommandArgs.AttrByIndex(0).ValueAsString("{0}://127.0.0.1:{1}".Args(SysConsts.APTERM_BINDING,
                                                                                                   SysConsts.DEFAULT_HOST_GOV_APPTERM_PORT));

                if (new Node(node).Binding.IsNullOrWhiteSpace())
                {
                    node = "{0}://{1}".Args(SysConsts.APTERM_BINDING, node);
                }

                if (new Node(node).Service.IsNullOrWhiteSpace())
                {
                    node = "{0}:{1}".Args(node, SysConsts.DEFAULT_HOST_GOV_APPTERM_PORT);
                }

                var file = app.CommandArgs["f", "file"].AttrByIndex(0).Value;

                if (file.IsNotNullOrWhiteSpace())
                {
                    if (!System.IO.File.Exists(file))
                    {
                        throw new SkyException("File not found:" + file);
                    }
                    if (!silent)
                    {
                        ConsoleUtils.Info("Reading from file: " + file);
                    }
                    file = System.IO.File.ReadAllText(file);
                    if (!silent)
                    {
                        ConsoleUtils.Info("Command text: " + file);
                    }
                }

                var txt = app.CommandArgs["t", "txt"].AttrByIndex(0).Value;

                if (txt.IsNotNullOrWhiteSpace())
                {
                    if (!silent)
                    {
                        ConsoleUtils.Info("Verbatim command text: " + txt);
                    }
                }

                var credentials = new IDPasswordCredentials(user, pwd);


                using (var client = new RemoteTerminal(app.Glue, node.ToResolvedServiceNode(true)))
                {
                    client.Headers.Add(new AuthenticationHeader(credentials));

                    var hinfo = client.Connect("{0}@{1}".Args(user, System.Environment.MachineName));
                    if (!silent)
                    {
                        var c = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("Connected. Use ';' at line end to submit statement, 'exit;' to disconnect");
                        Console.WriteLine("Type 'help;' for edification or '<command> /?;' for command-specific help");
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine(hinfo.WelcomeMsg);
                        Console.ForegroundColor = c;
                    }

                    if (txt.IsNotNullOrWhiteSpace() || file.IsNotNullOrWhiteSpace())
                    {
                        try
                        {
                            if (txt.IsNotNullOrWhiteSpace())
                            {
                                write(client.Execute(txt));
                            }
                            if (file.IsNotNullOrWhiteSpace())
                            {
                                write(client.Execute(file));
                            }
                        }
                        catch (RemoteException remoteError)
                        {
                            TerminalUtils.ShowRemoteException(remoteError);
                            Environment.ExitCode = -1;
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            if (!silent)
                            {
                                var c = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.Write("{0}@{1}@{2}>".Args(hinfo.TerminalName, hinfo.AppName, hinfo.Host));
                                Console.ForegroundColor = c;
                            }
                            var command = "";

                            while (true)
                            {
                                var ln = Console.ReadLine();
                                command += ln;
                                if (ln.EndsWith(";"))
                                {
                                    break;
                                }
                                if (!silent)
                                {
                                    var c = Console.ForegroundColor;
                                    Console.ForegroundColor = ConsoleColor.White;
                                    Console.Write(">");
                                    Console.ForegroundColor = c;
                                }
                            }

                            command = command.Remove(command.Length - 1, 1);

                            if (command == "exit")
                            {
                                break;
                            }

                            string response = null;

                            try
                            {
                                response = client.Execute(command);
                            }
                            catch (RemoteException remoteError)
                            {
                                TerminalUtils.ShowRemoteException(remoteError);
                                continue;
                            }
                            write(response);
                        }
                    }

                    var disconnectMessage = client.Disconnect();
                    if (!silent)
                    {
                        write(disconnectMessage);
                    }
                }
            }
        }//run
コード例 #13
0
ファイル: MainGUI.cs プロジェクト: swsk33/EZSetup
        private void install_Click(object sender, EventArgs e)
        {
            if (pathValue.Text.Equals(""))
            {
                MessageBox.Show("安装目录不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Directory.Exists(pathValue.Text.Substring(0, 3)))
            {
                MessageBox.Show("指定的安装目录所在驱动器不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Directory.Exists(pathValue.Text) && (Directory.GetFiles(pathValue.Text).Length != 0 || Directory.GetDirectories(pathValue.Text).Length != 0))
            {
                MessageBox.Show("指定的安装目录必须为空目录!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //开始执行安装
            mainTabPanel.SelectedIndex = 3;
            if (!Directory.Exists(pathValue.Text))
            {
                Directory.CreateDirectory(pathValue.Text);
            }
            long           totalSize = IOUtils.Get7zOriginSize(ConfigUtils.WORK_PLACE + "\\data.7z");
            TerminalResult result    = new TerminalResult();

            TerminalUtils.RunCommandAsynchronously("7z", "x " + TextUtils.SurroundByDoubleQuotes(ConfigUtils.WORK_PLACE + "\\data.7z") + " -o" + TextUtils.SurroundByDoubleQuotes(pathValue.Text), result);
            int    ratio = 0;
            string curFile;

            while (!result.Finished)
            {
                try
                {
                    DirInfo info = new DirInfo();
                    BinaryUtils.GetDirectoryInfo(pathValue.Text, info);
                    ratio = (int)((float)info.Size / totalSize * 100);
                    if (ratio > 100)
                    {
                        ratio = 100;
                    }
                    List <string> fileList = info.FileList;
                    if (fileList.Count > 0)
                    {
                        curFile          = fileList[fileList.Count - 1];
                        currentFile.Text = "正在释放:" + curFile.Substring(curFile.LastIndexOf("\\") + 1);
                    }
                }
                catch
                {
                    //none
                }
                finally
                {
                    processValue.Text = ratio + "%";
                    progressBar.Value = ratio;
                    Application.DoEvents();
                }
            }
            //安装完成,写入相应注册表和创建快捷方式
            if (ConfigUtils.GlobalConfigure.GenerateShortcut && addDesktopIcon.Checked)
            {
                foreach (string sitem in ConfigUtils.GlobalConfigure.ShortcutList)
                {
                    string[] shortInfo       = sitem.Split('|');               //分割后得到分别是原文件名、快捷方式名和运行参数(可能没有参数)
                    string   originFilePath  = pathValue.Text + "\\" + shortInfo[0];
                    string   destDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + shortInfo[1];
                    if (shortInfo.Length == 2)
                    {
                        IOUtils.CreateShortcut(originFilePath, destDesktopPath);
                    }
                    else
                    {
                        IOUtils.CreateShortcut(originFilePath, destDesktopPath, shortInfo[2]);
                    }
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title);
                    }
                    string destMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title + "\\" + shortInfo[1];
                    if (shortInfo.Length == 2)
                    {
                        IOUtils.CreateShortcut(originFilePath, destMenuPath);
                    }
                    else
                    {
                        IOUtils.CreateShortcut(originFilePath, destMenuPath, shortInfo[2]);
                    }
                }
            }
            if (ConfigUtils.GlobalConfigure.AddBootOption && addBootOption.Checked)
            {
                RegUtils.OperateBootOption(ConfigUtils.GlobalConfigure.Title, pathValue.Text + "\\" + ConfigUtils.GlobalConfigure.MainEXE, true);
            }
            //如果生成卸载程序,则加入注册表程序信息
            if (ConfigUtils.GlobalConfigure.GenerateUninstall)
            {
                AppUninstallInfo info = new AppUninstallInfo();
                info.DisplayName     = ConfigUtils.GlobalConfigure.Title;
                info.InstallPath     = pathValue.Text;
                info.UninstallString = pathValue.Text + "\\uninstall.exe";
                string iconPath = ConfigUtils.GlobalConfigure.MainEXE;
                if (iconPath.Equals(""))
                {
                    iconPath = "uninstall.exe";
                }
                info.DisplayIcon    = pathValue.Text + "\\" + iconPath;
                info.EstimatedSize  = totalSize / 1024;
                info.DisplayVersion = ConfigUtils.GlobalConfigure.Version;
                info.Publisher      = ConfigUtils.GlobalConfigure.Publisher;
                RegUtils.OperateAppUninstallItem(info, true);
                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title))
                {
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title);
                }
                IOUtils.CreateShortcut(pathValue.Text + "\\uninstall.exe", Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title + "\\卸载程序");
            }
            mainTabPanel.SelectedIndex = 4;
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: swsk33/EZSetup
        /// <summary>
        /// 安装时执行
        /// </summary>
        public static void DoInstall()
        {
            //开始执行安装
            if (!Directory.Exists(ConfigUtils.GlobalConfigure.InstallPath))
            {
                Directory.CreateDirectory(ConfigUtils.GlobalConfigure.InstallPath);
            }
            TerminalResult result = new TerminalResult();

            TerminalUtils.RunCommandAsynchronously("7z", "x " + TextUtils.SurroundByDoubleQuotes(ConfigUtils.WORK_PLACE + "\\data.7z") + " -o" + TextUtils.SurroundByDoubleQuotes(ConfigUtils.GlobalConfigure.InstallPath), result);
            //安装完成,写入相应注册表和创建快捷方式
            if (ConfigUtils.GlobalConfigure.GenerateShortcut)
            {
                foreach (string sitem in ConfigUtils.GlobalConfigure.ShortcutList)
                {
                    string[] shortInfo       = sitem.Split('|');               //分割后得到分别是原文件名、快捷方式名和运行参数(可能没有参数)
                    string   originFilePath  = ConfigUtils.GlobalConfigure.InstallPath + "\\" + shortInfo[0];
                    string   destDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + shortInfo[1];
                    if (shortInfo.Length == 2)
                    {
                        IOUtils.CreateShortcut(originFilePath, destDesktopPath);
                    }
                    else
                    {
                        IOUtils.CreateShortcut(originFilePath, destDesktopPath, shortInfo[2]);
                    }
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title);
                    }
                    string destMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title + "\\" + shortInfo[1];
                    if (shortInfo.Length == 2)
                    {
                        IOUtils.CreateShortcut(originFilePath, destMenuPath);
                    }
                    else
                    {
                        IOUtils.CreateShortcut(originFilePath, destMenuPath, shortInfo[2]);
                    }
                }
            }
            if (ConfigUtils.GlobalConfigure.AddBootOption)
            {
                RegUtils.OperateBootOption(ConfigUtils.GlobalConfigure.Title, ConfigUtils.GlobalConfigure.InstallPath + "\\" + ConfigUtils.GlobalConfigure.MainEXE, true);
            }
            //如果生成卸载程序,则加入注册表程序信息
            if (ConfigUtils.GlobalConfigure.GenerateUninstall)
            {
                AppUninstallInfo info = new AppUninstallInfo();
                info.DisplayName     = ConfigUtils.GlobalConfigure.Title;
                info.InstallPath     = ConfigUtils.GlobalConfigure.InstallPath;
                info.UninstallString = ConfigUtils.GlobalConfigure.InstallPath + "\\uninstall.exe";
                string iconPath = ConfigUtils.GlobalConfigure.MainEXE;
                if (iconPath.Equals(""))
                {
                    iconPath = "uninstall.exe";
                }
                info.DisplayIcon    = ConfigUtils.GlobalConfigure.InstallPath + "\\" + iconPath;
                info.EstimatedSize  = IOUtils.Get7zOriginSize(ConfigUtils.WORK_PLACE + "\\data.7z") / 1024;
                info.DisplayVersion = ConfigUtils.GlobalConfigure.Version;
                info.Publisher      = ConfigUtils.GlobalConfigure.Publisher;
                RegUtils.OperateAppUninstallItem(info, true);
                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title))
                {
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title);
                }
                IOUtils.CreateShortcut(ConfigUtils.GlobalConfigure.InstallPath + "\\uninstall.exe", Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms) + "\\" + ConfigUtils.GlobalConfigure.Title + "\\卸载程序");
            }
        }
コード例 #15
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);
        }
コード例 #16
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);
        }
コード例 #17
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");
 }
コード例 #18
0
 private void referNewSoftJson_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     TerminalUtils.RunCommand("cmd", "/c start https://www.newtonsoft.com/json");
 }
コード例 #19
0
 private void refer7z_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     TerminalUtils.RunCommand("cmd", "/c start https://www.7-zip.org/");
 }