Exemplo n.º 1
0
        /// <summary>
        /// Remove the program
        /// </summary>
        public string Uninstall()
        {
            if (IsFileLocked(new FileInfo(System.IO.Path.Combine(INSTALL_PATH, "Prog the robot.exe"))))
            {
                return("Please close Prog The Robot First");
            }

            RemoveDir(new string[] { PROGRAMS_PATH, $@"C:/Users/{Environment.UserName}/AppData/LocalLow/Jolan Aklin/Prog the robot" });

            FileAssociation fileAssociation = new FileAssociation("Prog The Robot");

            fileAssociation.RemoveExtension(".pr");

            fileAssociation = new FileAssociation("Prog The Robot Dev");
            fileAssociation.RemoveExtension(".pr");

            // create a batch to remove everything
            var          procId = Process.GetCurrentProcess().Id;
            StreamWriter stream = System.IO.File.CreateText(UNINSTALLBAT_PATH);

            stream.WriteLine($"Taskkill /F /PID {procId}");
            stream.WriteLine($"rmdir /S /Q \"{INSTALL_PATH}\"");
            stream.WriteLine("powershell -Command \"& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('Prog The Robot was successfully removed', 'Uninstaller', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}\"");
            stream.WriteLine($"del /Q \"{UNINSTALLBAT_PATH}\"");
            stream.Close();

            // start the batch
            Process process = new Process();

            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName       = UNINSTALLBAT_PATH;
            process.Start();

            System.Windows.Application.Current.Shutdown();

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// install the program, add start menu entry and add the file association
        /// </summary>
        /// <param name="CallBack">Called when the installation is finished</param>
        public async void InstallApp(GitHubReleaseFetcher.DownloadableFiles[] downloadedFiles, Action CallBack)
        {
            if (fileName == null)
            {
                PreInstall();
            }

            bool needToCreateProgTheRobotDevLink = false;
            bool needToCreateProgTheRobotLink    = false;

            bool devInstall   = false;
            bool soundInstall = false;

            foreach (GitHubReleaseFetcher.DownloadableFiles downloadedFile in downloadedFiles)
            {
                //unzip the downloaded Prog the robot release
                FileStream stream = System.IO.File.OpenRead(System.IO.Path.Combine(TEMP_PATH, downloadedFile.ToString()));
                string     path   = "";
                switch (downloadedFile)
                {
                case GitHubReleaseFetcher.DownloadableFiles.ProgTheRobot:
                    path = INSTALL_PATH;
                    needToCreateProgTheRobotLink = true;
                    break;

                case GitHubReleaseFetcher.DownloadableFiles.SoundPack:
                    path         = Path.Combine(INSTALL_PATH, "Prog the robot_Data", "sounds");
                    soundInstall = true;
                    break;

                case GitHubReleaseFetcher.DownloadableFiles.DemoPack:
                    path = $@"C:/Users/{Environment.UserName}/AppData/LocalLow/Jolan Aklin/Prog the robot/saves/";
                    break;

                case GitHubReleaseFetcher.DownloadableFiles.ProgTheRobotDev:
                    path       = Path.Combine(INSTALL_PATH, "dev");
                    devInstall = true;
                    needToCreateProgTheRobotDevLink = true;
                    break;
                }
                CreateDir(new string[] { path });
                Task t = new Task(() => { UnzipFromStream(stream, path); });
                t.Start();
                await t;
            }

            if (devInstall && soundInstall)
            {
                string devSound = Path.Combine(INSTALL_PATH, "dev", "Prog the robot_Data", "sounds");
                CreateDir(new string[] { devSound });
                DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(INSTALL_PATH, "Prog the robot_Data", "sounds"));
                foreach (FileInfo file in directoryInfo.GetFiles())
                {
                    file.CopyTo(Path.Combine(devSound, file.Name));
                }
            }

            RemoveDir(new string[] { TEMP_PATH });

            // create start menu entry for the program and the installer
            if (needToCreateProgTheRobotLink)
            {
                CreateStartMenuEntry(System.IO.Path.Combine(INSTALL_PATH, "Prog the robot.exe"), "Prog The Robot.lnk", "Launch Prog The Robot");
                CreateStartMenuEntry(System.IO.Path.Combine(INSTALL_PATH, fileName), "Prog The Robot installer.lnk", "Install, update and uninstall Prog The Robot");
            }

            if (needToCreateProgTheRobotDevLink)
            {
                CreateStartMenuEntry(System.IO.Path.Combine(INSTALL_PATH, "dev", "Prog the robot.exe"), "Prog The Robot Dev.lnk", "Prog The Robot Dev Edition");
            }

            // create the icon for the .pr files
            Stream fileImage = System.IO.File.Create(System.IO.Path.Combine(INSTALL_PATH, "FileLogo.ico"));

            fileImage.Write(Properties.Resources.FileLogo);
            fileImage.Close();

            FileAssociation fileAssociation;

            // create the file association for prog the robot dev
            if (needToCreateProgTheRobotDevLink)
            {
                fileAssociation = new FileAssociation("Prog The Robot Dev", "Prog The Robot project");
                fileAssociation.SetExtension(".pr", System.IO.Path.Combine(INSTALL_PATH, "dev", "Prog the robot.exe"), System.IO.Path.Combine(INSTALL_PATH, "FileLogo.ico"));
            }

            // create the file association for prog the robot
            if (needToCreateProgTheRobotLink)
            {
                fileAssociation = new FileAssociation("Prog The Robot", "Prog The Robot project");
                fileAssociation.SetExtension(".pr", System.IO.Path.Combine(INSTALL_PATH, "Prog the robot.exe"), System.IO.Path.Combine(INSTALL_PATH, "FileLogo.ico"));
            }

            CallBack?.Invoke();
        }