7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using System.Collections.Specialized;
34
using System.Diagnostics;
35
using System.Runtime.Serialization.Formatters.Binary;
37
namespace Mono.Addins.Database
39
internal class SetupProcess
41
internal static void ExecuteCommand (IProgressStatus monitor, string registryPath, string startupDir, string name, params string[] args)
43
string asm = new Uri (typeof(SetupProcess).Assembly.CodeBase).LocalPath;
44
string verboseParam = monitor.LogLevel.ToString ();
47
StringBuilder sb = new StringBuilder ();
48
sb.Append (verboseParam).Append (' ').Append (name);
49
foreach (string arg in args)
50
sb.Append (" \"").Append (arg).Append ("\"");
52
Process process = new Process ();
54
process.StartInfo = new ProcessStartInfo (asm, sb.ToString ());
56
asm = asm.Replace(" ", @"\ ");
57
process.StartInfo = new ProcessStartInfo ("mono", "--debug " + asm + " " + sb.ToString ());
59
process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
60
process.StartInfo.UseShellExecute = false;
61
process.StartInfo.CreateNoWindow = true;
62
process.StartInfo.RedirectStandardInput = true;
63
process.StartInfo.RedirectStandardOutput = true;
64
process.StartInfo.RedirectStandardError = true;
65
process.EnableRaisingEvents = true;
68
} catch (Exception ex) {
69
Console.WriteLine (ex);
73
process.StandardInput.WriteLine (registryPath);
74
process.StandardInput.WriteLine (startupDir);
75
process.StandardInput.Flush ();
77
// string rr = process.StandardOutput.ReadToEnd ();
78
// Console.WriteLine (rr);
80
StringCollection progessLog = new StringCollection ();
81
ProcessProgressStatus.MonitorProcessStatus (monitor, process.StandardOutput, progessLog);
82
process.WaitForExit ();
83
if (process.ExitCode != 0)
84
throw new ProcessFailedException (progessLog);
87
public static int Main (string[] args)
89
ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args[0]));
92
string registryPath = Console.In.ReadLine ();
93
string startupDir = Console.In.ReadLine ();
95
AddinDatabase.RunningSetupProcess = true;
96
AddinRegistry reg = new AddinRegistry (registryPath, startupDir);
100
string folder = args.Length > 2 ? args [2] : null;
101
if (folder.Length == 0) folder = null;
102
StringCollection filesToIgnore = new StringCollection ();
103
for (int n=3; n<args.Length; n++)
104
filesToIgnore.Add (args[n]);
105
reg.ScanFolders (monitor, folder, filesToIgnore);
108
reg.ParseAddin (monitor, args[2], args[3]);
111
} catch (Exception ex) {
112
monitor.ReportError ("Unexpected error in setup process", ex);
119
class ProcessFailedException: Exception
121
StringCollection progessLog;
123
public ProcessFailedException (StringCollection progessLog)
125
this.progessLog = progessLog;
128
public StringCollection ProgessLog {
129
get { return progessLog; }
132
public string LastLog {
133
get { return progessLog.Count > 0 ? progessLog [progessLog.Count - 1] : ""; }