~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Database/.svn/text-base/SetupProcess.cs.svn-base

  • Committer: Chris S.
  • Date: 2009-06-21 03:37:34 UTC
  • Revision ID: chris@szikszoy.com-20090621033734-ud2jdcd5pq9r3ue9
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// SetupProcess.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
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:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
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.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.Collections.Specialized;
 
32
using System.IO;
 
33
using System.Text;
 
34
using System.Diagnostics;
 
35
using System.Runtime.Serialization.Formatters.Binary;
 
36
 
 
37
namespace Mono.Addins.Database
 
38
{
 
39
        internal class SetupProcess
 
40
        {
 
41
                internal static void ExecuteCommand (IProgressStatus monitor, string registryPath, string startupDir, string name, params string[] args)
 
42
                {
 
43
                        string asm = new Uri (typeof(SetupProcess).Assembly.CodeBase).LocalPath;
 
44
                        string verboseParam = monitor.LogLevel.ToString ();
 
45
                        
 
46
                        // Arguments string
 
47
                        StringBuilder sb = new StringBuilder ();
 
48
                        sb.Append (verboseParam).Append (' ').Append (name);
 
49
                        foreach (string arg in args)
 
50
                                sb.Append (" \"").Append (arg).Append ("\"");
 
51
                        
 
52
                        Process process = new Process ();
 
53
                        if (Util.IsWindows)
 
54
                                process.StartInfo = new ProcessStartInfo (asm, sb.ToString ());
 
55
                        else {
 
56
                                asm = asm.Replace(" ", @"\ ");
 
57
                                process.StartInfo = new ProcessStartInfo ("mono", "--debug " + asm + " " + sb.ToString ());
 
58
                        }
 
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;
 
66
                        try {
 
67
                                process.Start ();
 
68
                        } catch (Exception ex) {
 
69
                                Console.WriteLine (ex);
 
70
                                throw;
 
71
                        }
 
72
                        
 
73
                        process.StandardInput.WriteLine (registryPath);
 
74
                        process.StandardInput.WriteLine (startupDir);
 
75
                        process.StandardInput.Flush ();
 
76
 
 
77
//                      string rr = process.StandardOutput.ReadToEnd ();
 
78
//                      Console.WriteLine (rr);
 
79
                        
 
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);
 
85
                }
 
86
                
 
87
                public static int Main (string[] args)
 
88
                {
 
89
                        ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args[0]));
 
90
                        
 
91
                        try {
 
92
                                string registryPath = Console.In.ReadLine ();
 
93
                                string startupDir = Console.In.ReadLine ();
 
94
                                
 
95
                                AddinDatabase.RunningSetupProcess = true;
 
96
                                AddinRegistry reg = new AddinRegistry (registryPath, startupDir);
 
97
                        
 
98
                                switch (args [1]) {
 
99
                                case "scan":
 
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);
 
106
                                        break;
 
107
                                case "get-desc":
 
108
                                        reg.ParseAddin (monitor, args[2], args[3]);
 
109
                                        break;
 
110
                                }
 
111
                        } catch (Exception ex) {
 
112
                                monitor.ReportError ("Unexpected error in setup process", ex);
 
113
                                return 1;
 
114
                        }
 
115
                        return 0;
 
116
                }
 
117
        }
 
118
        
 
119
        class ProcessFailedException: Exception
 
120
        {
 
121
                StringCollection progessLog;
 
122
                
 
123
                public ProcessFailedException (StringCollection progessLog)
 
124
                {
 
125
                        this.progessLog = progessLog;
 
126
                }
 
127
                
 
128
                public StringCollection ProgessLog {
 
129
                        get { return progessLog; }
 
130
                }
 
131
                
 
132
                public string LastLog {
 
133
                        get { return progessLog.Count > 0 ? progessLog [progessLog.Count - 1] : ""; }
 
134
                }
 
135
        }
 
136
}