/// <summary> /// Creates the update script on disk. /// </summary> /// <returns>ProcessStartInfo for the update script.</returns> public static ProcessStartInfo CreateUpdateScript() { try { string updateScriptPath = GetUpdateScriptPath(); string updateScriptSource = GetUpdateScriptSource(); File.WriteAllText(updateScriptPath, updateScriptSource); if (ChecksHandler.IsRunningOnUnix()) { UnixHandler.MakeExecutable(updateScriptPath); } ProcessStartInfo updateShellProcess = new ProcessStartInfo { FileName = updateScriptPath, UseShellExecute = false, RedirectStandardOutput = false, WindowStyle = ProcessWindowStyle.Hidden }; return(updateShellProcess); } catch (IOException ioex) { Log.Warn("Failed to create update script (IOException): " + ioex.Message); return(null); } }
/// <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); } }