dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Configuration.Install Assembly


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Configuration.Install AssemblyInstaller.cs, 1.2, 1.3 InstallContext.cs, 1.1, 1.2 ManagedInstallerClass.cs, 1.1, 1.2
Date: Fri, 08 Aug 2003 23:48:25 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Configuration.Install
In directory subversions:/tmp/cvs-serv5655/System.Configuration.Install

Modified Files:
        AssemblyInstaller.cs InstallContext.cs 
        ManagedInstallerClass.cs 
Log Message:


Implement the command-line handling for the "ilinstall" program.


Index: AssemblyInstaller.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Configuration.Install/AssemblyInstaller.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** AssemblyInstaller.cs        9 Aug 2003 01:53:29 -0000       1.2
--- AssemblyInstaller.cs        9 Aug 2003 03:48:22 -0000       1.3
***************
*** 203,207 ****
                        {
                                Initialize();
!                               // TODO
                        }
  
--- 203,207 ----
                        {
                                Initialize();
!                               base.Commit(savedState);
                        }
  
***************
*** 211,215 ****
                        {
                                Initialize();
!                               // TODO
                        }
  
--- 211,215 ----
                        {
                                Initialize();
!                               base.Install(stateSaver);
                        }
  
***************
*** 218,222 ****
                        {
                                Initialize();
!                               // TODO
                        }
  
--- 218,222 ----
                        {
                                Initialize();
!                               base.Rollback(savedState);
                        }
  
***************
*** 225,229 ****
                        {
                                Initialize();
!                               // TODO
                        }
  
--- 225,229 ----
                        {
                                Initialize();
!                               base.Uninstall(savedState);
                        }
  

Index: InstallContext.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Configuration.Install/InstallContext.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** InstallContext.cs   9 Aug 2003 01:36:36 -0000       1.1
--- InstallContext.cs   9 Aug 2003 03:48:22 -0000       1.2
***************
*** 44,47 ****
--- 44,52 ----
                                this.parameters = ParseCommandLine(commandLine);
                        }
+     internal InstallContext(StringDictionary parameters)
+                       {
+                               this.logFilePath = parameters["logfile"];
+                               this.parameters = parameters;
+                       }
  
      // Get the command-line parameters.
***************
*** 60,63 ****
--- 65,73 ----
                                if(value == null)
                                {
+                                       // Special check for "--x" forms of 
option names.
+                                       value = parameters["-" + 
paramName.ToLower()];
+                               }
+                               if(value == null)
+                               {
                                        return false;
                                }
***************
*** 104,107 ****
--- 114,127 ----
                        }
  
+       // Add to a string dictionary, overridding previous values.
+       private static void Add(StringDictionary dict, String name, String 
value)
+                       {
+                               if(dict[name] != null)
+                               {
+                                       dict.Remove(name);
+                               }
+                               dict[name] = value;
+                       }
+ 
      // Parse a command line into a string dictionary.
      protected static StringDictionary ParseCommandLine(String[] args)
***************
*** 129,134 ****
                                                                                
if((posn + 2) < args.Length)
                                                                                
{
!                                                                               
    dict.Add
!                                                                               
                (str.Substring(1).ToLower(),
                                                                                
                 "");
                                                                                
    ++posn;
--- 149,154 ----
                                                                                
if((posn + 2) < args.Length)
                                                                                
{
!                                                                               
    Add(dict,
!                                                                               
                str.Substring(1).ToLower(),
                                                                                
                 "");
                                                                                
    ++posn;
***************
*** 136,141 ****
                                                                                
else
                                                                                
{
!                                                                               
    dict.Add
!                                                                               
                (str.Substring(1).ToLower(),
                                                                                
                 args[posn + 2]);
                                                                                
    posn += 2;
--- 156,161 ----
                                                                                
else
                                                                                
{
!                                                                               
    Add(dict,
!                                                                               
                str.Substring(1).ToLower(),
                                                                                
                 args[posn + 2]);
                                                                                
    posn += 2;
***************
*** 145,149 ****
                                                                    {
                                                                                
// Option of the form "/name =value".
!                                                                               
dict.Add(str.Substring(1).ToLower(),
                                                                                
                 args[posn + 1].Substring(1));
                                                                                
++posn;
--- 165,169 ----
                                                                    {
                                                                                
// Option of the form "/name =value".
!                                                                               
Add(dict, str.Substring(1).ToLower(),
                                                                                
                 args[posn + 1].Substring(1));
                                                                                
++posn;
***************
*** 153,157 ****
                                                                {
                                                                    // Option 
of the form "/name".
!                                                                   
dict.Add(str.Substring(1).ToLower(), "");
                                                                }
                                                    }
--- 173,177 ----
                                                                {
                                                                    // Option 
of the form "/name".
!                                                                   Add(dict, 
str.Substring(1).ToLower(), "");
                                                                }
                                                    }
***************
*** 160,164 ****
                                                    {
                                                                // Option of 
the form "/name= value".
!                                                               
dict.Add(str.Substring(1, index - 1).ToLower(),
                                                                                
 args[posn + 1]);
                                                    }
--- 180,184 ----
                                                    {
                                                                // Option of 
the form "/name= value".
!                                                               Add(dict, 
str.Substring(1, index - 1).ToLower(),
                                                                                
 args[posn + 1]);
                                                    }
***************
*** 166,170 ****
                                                    {
                                                                // Option of 
the form "/name=value".
!                                                               
dict.Add(str.Substring(1, index - 1).ToLower(),
                                                                                
 str.Substring(index + 1));
                                                    }
--- 186,190 ----
                                                    {
                                                                // Option of 
the form "/name=value".
!                                                               Add(dict, 
str.Substring(1, index - 1).ToLower(),
                                                                                
 str.Substring(index + 1));
                                                    }
***************
*** 175,178 ****
--- 195,205 ----
                                return dict;
                    }
+     internal static StringDictionary ParseCommandLine
+                               (String[] args, int start, int length, out 
String[] newArgs)
+                       {
+                               newArgs = new String [length];
+                               Array.Copy(args, start, newArgs, 0, length);
+                               return ParseCommandLine(newArgs);
+                       }
  
  }; // class InstallContext

Index: ManagedInstallerClass.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Configuration.Install/ManagedInstallerClass.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ManagedInstallerClass.cs    9 Aug 2003 01:36:36 -0000       1.1
--- ManagedInstallerClass.cs    9 Aug 2003 03:48:22 -0000       1.2
***************
*** 23,26 ****
--- 23,29 ----
  {
  
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
  using System.Runtime.InteropServices;
  
***************
*** 31,44 ****
  public class ManagedInstallerClass : IManagedInstaller
  {
        // Entry point that is called by "InstallUtil".
        public static void InstallHelper(String[] args)
                        {
!                               // TODO
                        }
  
!       // Not used in this implementation.
        int IManagedInstaller.ManagedInstall(String commandLine, int hInstall)
                        {
!                               return 0;
                        }
  
--- 34,373 ----
  public class ManagedInstallerClass : IManagedInstaller
  {
+       // Internal state.
+       private String program;
+       private String[] args;
+       private String[] options;
+       private StringDictionary optionDict;
+       private String filename;
+       private bool uninstall;
+       private InstallContext context;
+ 
+       // Public constructor, for backwards compatibility.
+       // Use the "InstallHelper" method instead.
+       public ManagedInstallerClass() {}
+ 
+       // Internal constructor.
+       private ManagedInstallerClass(String[] args)
+                       {
+                               this.program = GetProgramName();
+                               if(args != null)
+                               {
+                                       this.args = args;
+                               }
+                               else
+                               {
+                                       this.args = new String [0];
+                               }
+                       }
+ 
+       // Get the name of the program that called us.
+       private static String GetProgramName()
+                       {
+                               String program = 
Environment.GetCommandLineArgs()[0];
+                               if(program.EndsWith(".exe") || 
program.EndsWith(".EXE"))
+                               {
+                                       program = program.Substring(0, 
program.Length - 4);
+                               }
+                               int index1 = program.LastIndexOf('/');
+                               int index2 = program.LastIndexOf('\\');
+                               if(index1 < index2)
+                               {
+                                       index1 = index2;
+                               }
+                               if(index1 != -1)
+                               {
+                                       program = program.Substring(index1 + 1);
+                               }
+                               return program;
+                       }
+ 
+       // Print version header information for this program.
+       private void VersionHeader()
+                       {
+                               Console.WriteLine
+                                       ("ILINSTALL {0} - IL Assembly 
Installer",
+                                        Environment.Version);
+                               Console.WriteLine
+                                       ("Copyright (c) 2003 Southern Storm 
Software, Pty Ltd.");
+                               Console.WriteLine();
+                       }
+ 
+       // Print version information for this program.
+       private void Version()
+                       {
+                               VersionHeader();
+                               Console.WriteLine
+                                       ("ILINSTALL comes with ABSOLUTELY NO 
WARRANTY.  This is free software,");
+                               Console.WriteLine
+                                       ("and you are welcome to redistribute 
it under the terms of the");
+                               Console.WriteLine
+                                       ("GNU General Public License.  See the 
file COPYING for further details.");
+                               Console.WriteLine();
+                               Console.WriteLine
+                                       ("Use the `--help' option to get help 
on the command-line options.");
+                       }
+ 
+       // Print usage information for this program.
+       private void Usage()
+                       {
+                               VersionHeader();
+                               Console.WriteLine
+                                       ("Usage: {0} [options] assembly 
[[options] assembly ...]",
+                                        program);
+                               Console.WriteLine();
+                               Console.WriteLine
+                                       ("    --install          or   -i");
+                               Console.WriteLine
+                                       ("        Install the assemblies 
(default).");
+                               Console.WriteLine
+                                       ("    --uninstall        or   -u");
+                               Console.WriteLine
+                                       ("        Uninstall the assemblies.");
+                               Console.WriteLine
+                                       ("    --logfile=file");
+                               Console.WriteLine
+                                       ("        Specify the name of the log 
file.");
+                               Console.WriteLine
+                                       ("    --logtoconsole");
+                               Console.WriteLine
+                                       ("        Also log messages to the 
console.");
+                               Console.WriteLine
+                                       ("    --showcallstack");
+                               Console.WriteLine
+                                       ("        Show the call stack when 
logging exceptions.");
+                               Console.WriteLine
+                                       ("    --version          or   -v");
+                               Console.WriteLine
+                                       ("        Print the version of this 
program.");
+                               Console.WriteLine
+                                       ("    --help assembly    or   -h 
assembly");
+                               Console.WriteLine
+                                       ("        Print help for a specific 
assembly.");
+                               Console.WriteLine
+                                       ("    --help             or   -h");
+                               Console.WriteLine
+                                       ("        Print this help message.");
+                               Console.WriteLine();
+                               Console.WriteLine
+                                       ("Options may also be specified with 
`/'.  e.g. `/uninstall'.");
+                       }
+ 
+       // Print help for a specific installer assembly.
+       private void PrintHelpFor(String filename)
+                       {
+                               AssemblyInstaller inst;
+                               inst = new AssemblyInstaller(filename, options);
+                               Console.WriteLine("Help options for {0}:", 
filename);
+                               Console.WriteLine();
+                               Console.Write(inst.HelpText);
+                       }
+ 
+       // Run the installation process for a specific assembly.
+       private void RunInstall(String filename)
+                       {
+                               // Load the installer assembly.
+                               AssemblyInstaller inst;
+                               inst = new AssemblyInstaller(filename, options);
+ 
+                               // Wrap the installer in a transaction.
+                               TransactedInstaller trans;
+                               trans = new TransactedInstaller();
+                               trans.Installers.Add(inst);
+ 
+                               // Install the assembly.
+                               IDictionary dict = new Hashtable();
+                               trans.Install(dict);
+ 
+                               // Write the state information, for later 
uninstall.
+                               // TODO
+                       }
+ 
+       // Run the uninstallation process for a specific assembly.
+       private void RunUninstall(String filename)
+                       {
+                               // Load the installer assembly.
+                               AssemblyInstaller inst;
+                               inst = new AssemblyInstaller(filename, options);
+ 
+                               // Wrap the installer in a transaction.
+                               TransactedInstaller trans;
+                               trans = new TransactedInstaller();
+                               trans.Installers.Add(inst);
+ 
+                               // Load the previous state information from the 
install.
+                               IDictionary dict = new Hashtable();
+                               // TODO
+ 
+                               // Install the assembly.
+                               trans.Uninstall(dict);
+                       }
+ 
+       // Run the installation process.
+       private int Install()
+                       {
+                               // Scan the command-line options in groups.
+                               int posn = 0;
+                               int start;
+                               String arg;
+                               bool both;
+                               uninstall = false;
+                               if(args.Length == 0)
+                               {
+                                       Usage();
+                                       return 1;
+                               }
+                               while(posn < args.Length)
+                               {
+                                       // Extract the next group of options.
+                                       start = posn;
+                                       while(posn < args.Length)
+                                       {
+                                               arg = args[posn];
+                                               if(arg.Length == 0)
+                                               {
+                                                       break;
+                                               }
+                                               if(arg[0] == '-')
+                                               {
+                                                       // Option that starts 
with "-".
+                                                       ++posn;
+                                                       if(arg.Length == 2 && 
arg[1] == '-')
+                                                       {
+                                                               // We use "--" 
to terminate the option
+                                                               // list just 
prior to a filename that
+                                                               // starts with 
"-" or "/".
+                                                               break;
+                                                       }
+                                               }
+                                               else if(arg[0] == '/')
+                                               {
+                                                       // Compatibility option 
that starts with "/".
+                                                       ++posn;
+                                               }
+                                               else if(arg[0] == '=')
+                                               {
+                                                       // May be specifying a 
value for a previous option.
+                                                       ++posn;
+                                               }
+                                               else if(posn > start && 
args[posn - 1].EndsWith("="))
+                                               {
+                                                       // Specifying a value 
for a previous option name.
+                                                       ++posn;
+                                               }
+                                               else
+                                               {
+                                                       // This is a filename.
+                                                       break;
+                                               }
+                                       }
+ 
+                                       // Parse the command line options that 
we just received.
+                                       optionDict = 
InstallContext.ParseCommandLine
+                                               (args, start, posn - start, out 
options);
+ 
+                                       // Extract the filename.
+                                       if(posn < args.Length)
+                                       {
+                                               filename = args[posn++];
+                                       }
+                                       else
+                                       {
+                                               filename = null;
+                                       }
+ 
+                                       // Create an install context for this 
option group.
+                                       context = new 
InstallContext(optionDict);
+ 
+                                       // Check for the "uninstall" and 
"install" flags.
+                                       both = false;
+                                       if(context.IsParameterTrue("uninstall") 
||
+                                          context.IsParameterTrue("u"))
+                                       {
+                                               uninstall = true;
+                                               both = true;
+                                       }
+                                       if(context.IsParameterTrue("install") ||
+                                          context.IsParameterTrue("i"))
+                                       {
+                                               if(both)
+                                               {
+                                                       Console.Error.WriteLine
+                                                               ("{0}: cannot 
specify both `--install' and " +
+                                                                
"`--uninstall'", program);
+                                                       return 1;
+                                               }
+                                               uninstall = false;
+                                       }
+ 
+                                       // Check for the version flag.
+                                       if(context.IsParameterTrue("version") ||
+                                          context.IsParameterTrue("v"))
+                                       {
+                                               Version();
+                                               return 0;
+                                       }
+ 
+                                       // Check for the help flag.
+                                       if(context.IsParameterTrue("help") ||
+                                          context.IsParameterTrue("h") ||
+                                          context.IsParameterTrue("?"))
+                                       {
+                                               if(filename == null)
+                                               {
+                                                       Usage();
+                                               }
+                                               else
+                                               {
+                                                       PrintHelpFor(filename);
+                                               }
+                                               continue;
+                                       }
+ 
+                                       // If we don't have a filename, then 
print the usage.
+                                       if(filename == null)
+                                       {
+                                               Usage();
+                                               return 1;
+                                       }
+ 
+                                       // Run the installation/uninstallation 
process.
+                                       if(uninstall)
+                                       {
+                                               RunUninstall(filename);
+                                       }
+                                       else
+                                       {
+                                               RunInstall(filename);
+                                       }
+                               }
+                               return 0;
+                       }
+ 
        // Entry point that is called by "InstallUtil".
        public static void InstallHelper(String[] args)
                        {
!                               ManagedInstallerClass inst;
!                               inst = new ManagedInstallerClass(args);
!                               int exitCode = inst.Install();
!                               if(exitCode != 0)
!                               {
!                                       Environment.Exit(exitCode);
!                               }
                        }
  
!       // Perform a managed install - this entry point is not recommended.
!       // It is provided for backwards compatibility only.
        int IManagedInstaller.ManagedInstall(String commandLine, int hInstall)
                        {
!                               this.program = GetProgramName();
!                               if(commandLine != null && commandLine.Length > 
0)
!                               {
!                                       this.args = commandLine.Split(' ');
!                               }
!                               else
!                               {
!                                       this.args = new String [0];
!                               }
!                               return Install();
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]