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
process.StartInfo = new ProcessStartInfo ("mono", "--debug " + asm + " " + sb.ToString ());
57
process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
58
process.StartInfo.UseShellExecute = false;
59
process.StartInfo.RedirectStandardInput = true;
60
process.StartInfo.RedirectStandardOutput = true;
61
process.StartInfo.RedirectStandardError = true;
62
process.EnableRaisingEvents = true;
65
} catch (Exception ex) {
66
Console.WriteLine (ex);
70
process.StandardInput.WriteLine (registryPath);
71
process.StandardInput.WriteLine (startupDir);
72
process.StandardInput.Flush ();
74
// string rr = process.StandardOutput.ReadToEnd ();
75
// Console.WriteLine (rr);
77
StringCollection progessLog = new StringCollection ();
78
ProcessProgressStatus.MonitorProcessStatus (monitor, process.StandardOutput, progessLog);
79
process.WaitForExit ();
80
if (process.ExitCode != 0)
81
throw new ProcessFailedException (progessLog);
84
public static int Main (string[] args)
86
ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args[0]));
89
string registryPath = Console.In.ReadLine ();
90
string startupDir = Console.In.ReadLine ();
92
AddinDatabase.RunningSetupProcess = true;
93
AddinRegistry reg = new AddinRegistry (registryPath, startupDir);
97
string folder = args.Length > 2 ? args [2] : null;
98
if (folder.Length == 0) folder = null;
99
StringCollection filesToIgnore = new StringCollection ();
100
for (int n=3; n<args.Length; n++)
101
filesToIgnore.Add (args[n]);
102
reg.ScanFolders (monitor, folder, filesToIgnore);
105
reg.ParseAddin (monitor, args[2], args[3]);
108
} catch (Exception ex) {
109
monitor.ReportError ("Unexpected error in setup process", ex);
116
class ProcessFailedException: Exception
118
StringCollection progessLog;
120
public ProcessFailedException (StringCollection progessLog)
122
this.progessLog = progessLog;
125
public StringCollection ProgessLog {
126
get { return progessLog; }
129
public string LastLog {
130
get { return progessLog.Count > 0 ? progessLog [progessLog.Count - 1] : ""; }