2
// ConsoleAddinInstaller.cs
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.
30
using System.Collections;
32
namespace Mono.Addins.Setup
34
public class ConsoleAddinInstaller: IAddinInstaller
40
public ConsoleAddinInstaller ()
44
public bool UserPrompt {
45
get { return prompt; }
48
if (prompt && logLevel == 0)
54
get { return logLevel; }
55
set { logLevel = value; }
58
void IAddinInstaller.InstallAddins (AddinRegistry reg, string message, string[] addinIds)
61
if (message != null && message.Length > 0) {
62
Console.WriteLine (message);
64
Console.WriteLine ("Additional extensions are required to perform this operation.");
67
ArrayList entries = new ArrayList ();
68
SetupService setup = new SetupService (reg);
72
foreach (string id in addinIds) {
73
string name = Addin.GetIdName (id);
74
string version = Addin.GetIdVersion (id);
75
AddinRepositoryEntry[] ares = setup.Repositories.GetAvailableAddin (name, version);
76
if (ares.Length == 0) {
81
entries.Add (ares[0]);
83
if (idNotFound != null) {
85
throw new InstallException ("Add-in '" + idNotFound + "' not found in the registered add-in repositories");
87
Console.WriteLine ("The add-in '" + idNotFound + "' could not be found in the registered repositories.");
88
Console.WriteLine ("The repository indices may be outdated.");
89
if (!Confirm ("Do you wan't to update them now?"))
90
throw new InstallException ("Add-in '" + idNotFound + "' not found in the registered add-in repositories");
92
setup.Repositories.UpdateAllRepositories (new ConsoleProgressStatus (logLevel));
96
while (idNotFound != null);
99
Console.WriteLine ("The following add-ins will be installed:");
100
foreach (AddinRepositoryEntry addin in entries)
101
Console.WriteLine (" - " + addin.Addin.Name + " v" + addin.Addin.Version);
104
if (!Confirm ("Do you want to continue with the installation?"))
105
throw new InstallException ("Installation cancelled");
108
setup.Install (new ConsoleProgressStatus (logLevel), (AddinRepositoryEntry[]) entries.ToArray (typeof(AddinRepositoryEntry)));
111
bool Confirm (string msg)
115
Console.Write (msg + " (Y/n): ");
116
res = Console.ReadLine ();
117
if (res.Length > 0 && res.ToLower()[0] == 'n')
119
} while (res.Length > 0 && res.ToLower()[0] != 'y');