コード例 #1
0
        /// <summary>
        /// Gets the deprecated old manifests' path on disk.
        /// </summary>
        /// <returns>The deprecated old manifest's path.</returns>
        private static string GetDeprecatedOldGameManifestPath()
        {
            string oldManifestPath = String.Format(@"{0}LauncherManifest.txt.old",
                                                   ConfigHandler.GetLocalDir());

            return(oldManifestPath);
        }
コード例 #2
0
        /// <summary>
        /// Gets the old launchpad manifests' path on disk.
        /// </summary>
        /// <returns>The old launchpad manifest's path.</returns>
        public static string GetOldLaunchpadManifestPath()
        {
            string oldManifestPath = String.Format(@"{0}LaunchpadManifest.txt.old",
                                                   ConfigHandler.GetLocalDir());

            return(oldManifestPath);
        }
コード例 #3
0
        /// <summary>
        /// Gets the game manifests' path on disk.
        /// </summary>
        /// <returns>The game manifest path.</returns>
        public static string GetGameManifestPath()
        {
            string manifestPath = String.Format(@"{0}GameManifest.txt",
                                                ConfigHandler.GetLocalDir());

            return(manifestPath);
        }
コード例 #4
0
ファイル: LauncherHandler.cs プロジェクト: tonbz/Launchpad
        /// <summary>
        /// Extracts the bundled update script and populates the variables in it
        /// with the data needed for the update procedure.
        /// </summary>
        private static string GetUpdateScriptSource()
        {
            // Load the script from the embedded resources
            Assembly localAssembly = Assembly.GetExecutingAssembly();

            string scriptSource = "";
            string resourceName = GetUpdateScriptResourceName();

            using (Stream resourceStream = localAssembly.GetManifestResourceStream(resourceName))
            {
                if (resourceStream != null)
                {
                    using (StreamReader reader = new StreamReader(resourceStream))
                    {
                        scriptSource = reader.ReadToEnd();
                    }
                }
            }

            // Replace the variables in the script with actual data
            const string TempDirectoryVariable         = "%temp%";
            const string LocalInstallDirectoryVariable = "%localDir%";
            const string LocalExecutableName           = "%launchpadExecutable%";

            string transientScriptSource = scriptSource;

            transientScriptSource = transientScriptSource.Replace(TempDirectoryVariable, Path.GetTempPath());
            transientScriptSource = transientScriptSource.Replace(LocalInstallDirectoryVariable, ConfigHandler.GetLocalDir());
            transientScriptSource = transientScriptSource.Replace(LocalExecutableName, Path.GetFileName(localAssembly.Location));

            return(transientScriptSource);
        }
コード例 #5
0
ファイル: ManifestHandler.cs プロジェクト: halbich/Launchpad
        /// <summary>
        /// Gets the deprecated old manifests' path on disk.
        /// </summary>
        /// <returns>The deprecated old manifest's path.</returns>
        private static string GetDeprecatedOldGameManifestPath()
        {
            string oldManifestPath = $@"{ConfigHandler.GetLocalDir()}LauncherManifest.txt.old";

            return(oldManifestPath);
        }
コード例 #6
0
ファイル: ManifestHandler.cs プロジェクト: halbich/Launchpad
        /// <summary>
        /// Gets the old launchpad manifests' path on disk.
        /// </summary>
        /// <returns>The old launchpad manifest's path.</returns>
        public static string GetOldLaunchpadManifestPath()
        {
            string oldManifestPath = $@"{ConfigHandler.GetLocalDir()}LaunchpadManifest.txt.old";

            return(oldManifestPath);
        }
コード例 #7
0
ファイル: ManifestHandler.cs プロジェクト: halbich/Launchpad
        /// <summary>
        /// Gets the launchpad manifests' path on disk.
        /// </summary>
        /// <returns>The launchpad manifest path.</returns>
        public static string GetLaunchpadManifestPath()
        {
            string manifestPath = $@"{ConfigHandler.GetLocalDir()}LaunchpadManifest.txt";

            return(manifestPath);
        }
コード例 #8
0
        /// <summary>
        /// Creates the update script on disk.
        /// </summary>
        /// <returns>ProcessStartInfo for the update script.</returns>
        public static ProcessStartInfo CreateUpdateScript()
        {
            try
            {
                //maintain the executable name if it was renamed to something other than 'Launchpad'
                string assemblyPath   = Assembly.GetEntryAssembly().Location;
                string executableName = Path.GetFileName(assemblyPath);

                if (ChecksHandler.IsRunningOnUnix())
                {
                    //creating a .sh script
                    string scriptPath = String.Format(@"{0}launchpadupdate.sh",
                                                      Path.GetTempPath());


                    using (FileStream updateScript = File.Create(scriptPath))
                    {
                        using (TextWriter tw = new StreamWriter(updateScript))
                        {
                            string copyCom = String.Format("cp -rf {0} {1}",
                                                           Path.GetTempPath() + "launchpad/launcher/*",
                                                           ConfigHandler.GetLocalDir());

                            string delCom = String.Format("rm -rf {0}",
                                                          Path.GetTempPath() + "launchpad");

                            string dirCom    = String.Format("cd {0}", ConfigHandler.GetLocalDir());
                            string launchCom = String.Format(@"nohup ./{0} &", executableName);
                            tw.WriteLine(@"#!/bin/sh");
                            tw.WriteLine("sleep 5");
                            tw.WriteLine(copyCom);
                            tw.WriteLine(delCom);
                            tw.WriteLine(dirCom);
                            tw.WriteLine("chmod +x " + executableName);
                            tw.WriteLine(launchCom);
                        }
                    }

                    UnixHandler.MakeExecutable(scriptPath);


                    //Now create some ProcessStartInfo for this script
                    ProcessStartInfo updateShellProcess = new ProcessStartInfo();

                    updateShellProcess.FileName               = scriptPath;
                    updateShellProcess.UseShellExecute        = false;
                    updateShellProcess.RedirectStandardOutput = false;
                    updateShellProcess.WindowStyle            = ProcessWindowStyle.Hidden;

                    return(updateShellProcess);
                }
                else
                {
                    //creating a .bat script
                    string scriptPath = String.Format(@"{0}launchpadupdate.bat",
                                                      Path.GetTempPath());

                    using (FileStream updateScript = File.Create(scriptPath))
                    {
                        using (TextWriter tw = new StreamWriter(updateScript))
                        {
                            //write commands to the script
                            //wait three seconds, then copy the new executable
                            tw.WriteLine(String.Format(@"timeout 3 & xcopy /e /s /y ""{0}\launchpad\launcher"" ""{1}"" && rmdir /s /q {0}\launchpad",
                                                       Path.GetTempPath(),
                                                       ConfigHandler.GetLocalDir()));

                            //then start the new executable
                            tw.WriteLine(String.Format(@"start {0}", executableName));
                            tw.Close();
                        }
                    }

                    ProcessStartInfo updateBatchProcess = new ProcessStartInfo();

                    updateBatchProcess.FileName               = scriptPath;
                    updateBatchProcess.UseShellExecute        = true;
                    updateBatchProcess.RedirectStandardOutput = false;
                    updateBatchProcess.WindowStyle            = ProcessWindowStyle.Hidden;

                    return(updateBatchProcess);
                }
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in CreateUpdateScript(): " + ioex.Message);

                return(null);
            }
        }