/// <summary> /// Dispose: free owned resources. /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (disposing) { // Resources created by Designer. if (components != null) { components.Dispose(); } // Named pipe if (pstream != null) { try { pstream.Close(); pstream.Dispose(); } catch { } } } base.Dispose(disposing); }
/// <summary> /// Runs as LOCAL SYSTEM from temp path; receives info from updater UI; checks package; executes installer. /// </summary> public static void Work() { // The service pipe we're listening through. NamedPipeStream pstream = null; try { // Create service pipe FileLogger.Instance.LogInfo("Creating named pipe."); FileSecurity pipeSecurity = new FileSecurity(); pipeSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier("S-1-5-11"), FileSystemRights.FullControl, AccessControlType.Allow)); pstream = NamedPipeStream.Create(Magic.ServiceShortName, NamedPipeStream.ServerMode.Bidirectional, pipeSecurity); // Wait for client (updater UI) to connect; but not too long. FileLogger.Instance.LogInfo("Waiting for client to connect."); if (!doListen(ref pstream)) { throw new Exception("Client didn't show up; tired of waiting."); } FileLogger.Instance.LogInfo("Client connected, reading paths and hash."); // Read location of downloaded installer and its file hash. string fname, fhash; doReadRequest(pstream, out fname, out fhash); // Verify signature FileLogger.Instance.LogInfo("Info received; verifying signature."); if (!SignatureCheck.VerifySignature(new FileInfo(fname), fhash)) { throw new Exception("Signature incorrect."); } FileLogger.Instance.LogInfo("Installer signature OK; launching installer"); // Let caller know we've started installer pstream.WriteByte(Magic.SrvCodeInstallStarted); // Launch installer int exitCode = doRunInstaller(fname); FileLogger.Instance.LogInfo("Installer returned exit code " + exitCode.ToString()); // Exit code 1 is failure if (exitCode == 1) { throw new Exception("Installer failed."); } // We've succeeded; let caller know. pstream.WriteByte(Magic.SrvCodeSuccess); FileLogger.Instance.LogInfo("Finished with success; quitting."); } catch { // Upon error, return failure code to caller. if (pstream != null) { try { pstream.WriteByte(Magic.SrvCodeFail); } catch { } } throw; } finally { // Close & dispose of service pipe before we exit left. if (pstream != null) { try { pstream.Close(); pstream.Dispose(); pstream = null; } catch { } } } }