~ubuntu-branches/ubuntu/karmic/mono-addins/karmic

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Database/SetupProcess.cs

  • Committer: Bazaar Package Importer
  • Author(s): Mirco Bauer
  • Date: 2007-07-14 12:07:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070714120748-2elczfsjlrdsrpms
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

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
                                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;
 
63
                        try {
 
64
                                process.Start ();
 
65
                        } catch (Exception ex) {
 
66
                                Console.WriteLine (ex);
 
67
                                throw;
 
68
                        }
 
69
                        
 
70
                        process.StandardInput.WriteLine (registryPath);
 
71
                        process.StandardInput.WriteLine (startupDir);
 
72
                        process.StandardInput.Flush ();
 
73
 
 
74
//                      string rr = process.StandardOutput.ReadToEnd ();
 
75
//                      Console.WriteLine (rr);
 
76
                        
 
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);
 
82
                }
 
83
                
 
84
                public static int Main (string[] args)
 
85
                {
 
86
                        ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args[0]));
 
87
                        
 
88
                        try {
 
89
                                string registryPath = Console.In.ReadLine ();
 
90
                                string startupDir = Console.In.ReadLine ();
 
91
                                
 
92
                                AddinDatabase.RunningSetupProcess = true;
 
93
                                AddinRegistry reg = new AddinRegistry (registryPath, startupDir);
 
94
                        
 
95
                                switch (args [1]) {
 
96
                                case "scan":
 
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);
 
103
                                        break;
 
104
                                case "get-desc":
 
105
                                        reg.ParseAddin (monitor, args[2], args[3]);
 
106
                                        break;
 
107
                                }
 
108
                        } catch (Exception ex) {
 
109
                                monitor.ReportError ("Unexpected error in setup process", ex);
 
110
                                return 1;
 
111
                        }
 
112
                        return 0;
 
113
                }
 
114
        }
 
115
        
 
116
        class ProcessFailedException: Exception
 
117
        {
 
118
                StringCollection progessLog;
 
119
                
 
120
                public ProcessFailedException (StringCollection progessLog)
 
121
                {
 
122
                        this.progessLog = progessLog;
 
123
                }
 
124
                
 
125
                public StringCollection ProgessLog {
 
126
                        get { return progessLog; }
 
127
                }
 
128
                
 
129
                public string LastLog {
 
130
                        get { return progessLog.Count > 0 ? progessLog [progessLog.Count - 1] : ""; }
 
131
                }
 
132
        }
 
133
}