// (c) 2005 kp@kp73.com
using System;
using System.Configuration.Install;
using System.IO;
using System.Collections;
using System.Diagnostics;
namespace KP.Tetris.SetupMce.CustomAction{
[System.ComponentModel.RunInstallerAttribute(true)]
public class Regeister : Installer
{
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
try
{
Debug.WriteLine("Install custom action " + this.ToString());
string applicationFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]);
Debug.WriteLine("Install application folder: " + applicationFolder);
Update(applicationFolder, true);
}
catch (Exception e)
{
Debug.WriteLine("Install error: " + e.Message);
}
}
public override void Install(IDictionary stateSaver)
{
base.Install (stateSaver);
try
{
Debug.WriteLine("Install custom action " + this.ToString());
string applicationFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]);
Debug.WriteLine("Install application folder: " + applicationFolder);
Update(applicationFolder);
}
catch (Exception e)
{
Debug.WriteLine("Install error: " + e.Message + e.StackTrace);
}
}
public static void Update(string applicationFolder)
{
Update(applicationFolder, false);
}
public static void Update(string applicationFolder, bool unregister)
{
string unreg = null;
string xml = null;
string xmlFilePath = Path.Combine(applicationFolder, @"RegisterDotNETris.xml");
if (unregister) unreg = @"/u ";
Debug.WriteLine("Install reading file: " + xmlFilePath);
using (FileStream s = File.OpenRead(xmlFilePath))
{
StreamReader r = new StreamReader(s);
xml = r.ReadToEnd();
}
xml = xml.Replace(@"{APPLICATIONPATH}", applicationFolder);
FileStream outputStream = File.Create(xmlFilePath);
StreamWriter outputWriter = new StreamWriter(outputStream);
outputWriter.Write(xml);
outputWriter.Flush();
outputWriter.Close();
string registerExePath = Path.Combine(
Environment.GetEnvironmentVariable("SYSTEMROOT"),
@"eHome\RegisterMCEApp.bat ");
Process.Start(registerExePath,
string.Format("{0} \"{1}\"", unreg, xmlFilePath));
// Process proc = new Process();
// proc.EnableRaisingEvents = false;
// proc.StartInfo.Arguments = string.Concat(unreg, " \"", xmlFilePath,"\"");
// proc.StartInfo.FileName = registerExePath;
// Debug.WriteLine("Install register command: " + proc.StartInfo.FileName);
// Debug.WriteLine("Install register command args: " + proc.StartInfo.Arguments);
// proc.Start();
// proc.WaitForExit();
// Debug.WriteLine(proc.StandardOutput);
// Debug.WriteLine(proc.StandardError);
Debug.WriteLine("Install update complete.");
}
}
}
|