bool StartClient() { if (string.IsNullOrEmpty(m_CompleteWULoc)) { throw new Exception("The wyUpdate executable path supplied is not valid. Make sure wyUpdate exists on disk."); } // get the unique pipe name (the last 246 chars of the complete path) string pipeName = UpdateHelperData.PipenameFromFilename(m_CompleteWULoc); // first try to connect to the pipe if (!pipeClient.Connected) { pipeClient.Connect(pipeName); } if (pipeClient.Connected) { // request the processId if (!RetrySend((new UpdateHelperData(UpdateAction.GetwyUpdateProcessID)).GetByteArray())) { throw new Exception("Failed to get the wyUpdate Process ID."); } return(true); } if (!File.Exists(m_CompleteWULoc)) { throw new Exception("The wyUpdate executable was not found: " + m_CompleteWULoc); } ClientProcess = new Process { StartInfo = { FileName = m_CompleteWULoc, // start the client in automatic update mode (a.k.a. wait mode) Arguments = "/autoupdate", WindowStyle = ProcessWindowStyle.Hidden } }; if (!string.IsNullOrEmpty(ExtraArguments)) { ClientProcess.StartInfo.Arguments += " " + ExtraArguments; } ClientProcess.Start(); TryToConnectToPipe(pipeName); return(pipeClient.Connected); }
void StartNewSelfAndClose() { bool checkForClients = false; // when this function is called in the constructor // (i.e. before the handle for the form is created) // then the pipeserver will not have yet been created if (!updateHelper.RunningServer) { checkForClients = true; updateHelper.StartPipeServer(this); } Process clientProcess = new Process { StartInfo = { FileName = newSelfLocation, //NOTE: (Very goddamn important - change this and die) // Arguments must have the "clear space" before the closing quote after // baseDirectory. "Why?" you ask, because Windows is the offspring // of a Unicorn and an Angel. Everyone knows that Angels don't // respect backslash-quote combos. // And Unicorns are racists. // The non-absurd reason is that if you have a baseDirectory variable with // a trailing slash then a quote character adjacent to this slash (i.e. // with no space between the slash and quote) the commandline args // get fubar-ed. A base directory with a trailing slash is valid // input, thus the slash-space-quote combo must remain. // start the client in automatic update mode (a.k.a. wait mode) Arguments = "-cdata:\"" + clientFileLoc + "\" -basedir:\"" + baseDirectory + " \" /autoupdate /ns", WindowStyle = ProcessWindowStyle.Hidden } }; clientProcess.Start(); if (checkForClients) { // there must be at least one client running to receive this message int timeSpent = 0; while (updateHelper.TotalConnectedClients == 0) { // if we've already waited 30 seconds, we've wait long enough // something has gone wrong with the AutomaticUpdater control // no point in waiting around any longer. if (timeSpent == 30000) { break; } // wait 1/3 of a second timeSpent += 300; Thread.Sleep(300); } } // tell all the clients that there's a new wyUpdate updateHelper.SendNewWyUpdate(UpdateHelperData.PipenameFromFilename(newSelfLocation), clientProcess.Id); CancelUpdate(true); }