Advertisement
Guest User

Dan Olivares

a guest
Sep 19th, 2010
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine(
  13.                 "This program will copy OpenSim.ini.example to OpenSim.ini, StandaloneCommon.ini.example to StandaloneCommon.ini and append the proper value to OpenSim.ini so that OpenSimulator starts up in Basic Localhost Standalone Mode.   Run this only just after you've downloaded the source");
  14.             Console.Write("\nWould you like to Continue? y/n[y]:");
  15.             ConsoleKeyInfo keyResult = Console.ReadKey();
  16.            
  17.            
  18.                 if (keyResult.Key == ConsoleKey.N)
  19.                     return;
  20.            
  21.             ConfigFolders folders = GetConfigFolders();
  22.  
  23.             if (!folders.FoundResult)
  24.             {
  25.                 Console.WriteLine("\nThis program couldn't figure out where the files are located that it needs to change.  Please put this program in either the opensim directory or the bin directory and start again.   \n\nThis program will now exit.\n");
  26.                 //readresult = Console.ReadKey();
  27.                 keyResult = Console.ReadKey();
  28.                 return;
  29.             }
  30.  
  31.             // Check for example files
  32.  
  33.             if (!CheckForExampleFile(folders.BinFolder,"OpenSim.ini.example"))
  34.             {
  35.                 Console.WriteLine("\nThis program couldn't find the OpenSim.ini.example file it needs to copy.  Please verify that you have a complete source tree.   \n\nThis program will now exit.\n");
  36.                 keyResult = Console.ReadKey();
  37.                 return;
  38.             }
  39.  
  40.             if (!CheckForExampleFile(folders.ConfigIncludeFolder, "StandaloneCommon.ini.example"))
  41.             {
  42.                 Console.WriteLine("\nThis program couldn't find the StandaloneCommon.ini.example file it needs to copy.  Please verify that you have a complete source tree.   \n\nThis program will now exit.\n");
  43.                 keyResult = Console.ReadKey();
  44.                 return;
  45.             }
  46.  
  47.             // Check to see if the config files already exist so we don't overwrite them.
  48.  
  49.             if (!CheckForAndRemoveFile(folders.BinFolder,"OpenSim.ini"))
  50.             {
  51.                 return;
  52.             }
  53.  
  54.             if (!CheckForAndRemoveFile(folders.ConfigIncludeFolder, "StandaloneCommon.ini"))
  55.             {
  56.                 return;
  57.             }
  58.  
  59.             // Copy the example files into the destination.
  60.  
  61.             try
  62.             {
  63.                 File.Copy(Path.Combine(folders.BinFolder, "OpenSim.ini.example"),
  64.                           Path.Combine(folders.BinFolder, "OpenSim.ini"));
  65.  
  66.  
  67.             }
  68.             catch (Exception)
  69.             {
  70.                 Console.WriteLine("\nThere was a problem copying OpenSim.ini.example.  This is usually a permissions problem.   \n\nThis program will now exit.\n");
  71.                 keyResult = Console.ReadKey();
  72.                 return;
  73.             }
  74.  
  75.             try
  76.             {
  77.                 File.Copy(Path.Combine(folders.ConfigIncludeFolder, "StandaloneCommon.ini.example"),
  78.                           Path.Combine(folders.ConfigIncludeFolder, "StandaloneCommon.ini"));
  79.             }
  80.             catch (Exception)
  81.             {
  82.                 Console.WriteLine("\nThere was a problem copying StandaloneCommon.ini.example.  This is usually a permissions problem.   \n\nThis program will now exit.\n");
  83.                 keyResult = Console.ReadKey();
  84.                 return;
  85.             }
  86.  
  87.             try
  88.             {
  89.  
  90.  
  91.                 // Append the standalone architecture line
  92.                 StreamWriter sw = File.AppendText(Path.Combine(folders.BinFolder, "OpenSim.ini"));
  93.                 sw.WriteLine("Include-Architecture = \"config-include/Standalone.ini\"");
  94.                 sw.Flush();
  95.                 sw.Close();
  96.                 sw.Dispose();
  97.             }
  98.             catch (Exception)
  99.             {
  100.                 Console.WriteLine("\nThere was a problem appending to OpenSim.ini.  This is usually a permissions problem.   \n\nThis program will now exit.\n");
  101.                 keyResult = Console.ReadKey();
  102.                 return;
  103.             }
  104.  
  105.             Console.WriteLine("\n\nOK, All Succeeded.   Next, Compile OpenSimulator if you have not already and run OpenSim.exe");
  106.             keyResult = Console.ReadKey();
  107.  
  108.         }
  109.  
  110.         private static ConfigFolders GetConfigFolders()
  111.         {
  112.             string lBinFolder = ".";
  113.             string lConfigIncludeFolder = ".";
  114.             string lCurrentDirectory = ".";
  115.            
  116.             if (File.Exists(Path.Combine(lCurrentDirectory,"prebuild.xml")) && Directory.Exists(Path.Combine(".","bin")))
  117.             {
  118.                 // We're in the regular OpenSim directory                
  119.                 lBinFolder = Path.Combine(".","bin");
  120.                 lConfigIncludeFolder = Path.Combine(Path.Combine(".","bin"), "config-include");
  121.                 lCurrentDirectory = ".";
  122.                 ConfigFolders retFolders = new ConfigFolders(){BinFolder = lBinFolder,ConfigIncludeFolder=lConfigIncludeFolder,FoundResult=true};
  123.                 return retFolders;
  124.             }
  125.  
  126.             if (Directory.Exists(Path.Combine(".","config-include")))
  127.             {
  128.                 lBinFolder = ".";
  129.                 lConfigIncludeFolder = Path.Combine(".","config-include");
  130.                 ConfigFolders retFolders = new ConfigFolders() { BinFolder = lBinFolder, ConfigIncludeFolder = lConfigIncludeFolder, FoundResult = true };
  131.                 return retFolders;
  132.             }
  133.             ConfigFolders gretFolders = new ConfigFolders();
  134.             return gretFolders;
  135.  
  136.         }
  137.  
  138.         private static bool CheckForAndRemoveFile(string filepath,string filename)
  139.         {
  140.             ConsoleKeyInfo keyResult;
  141.             if (File.Exists(Path.Combine(filepath, filename)))
  142.             {
  143.                 Console.WriteLine(String.Format("\n WARNING: {0} already exists.",filename));
  144.                 Console.Write("Would you like to overwrite it? y/n[n]:");
  145.                 keyResult = Console.ReadKey();
  146.                 if (keyResult.Key != ConsoleKey.Y)
  147.                 {
  148.                     Console.WriteLine("This program will now exit.\n");
  149.                     keyResult = Console.ReadKey();
  150.                     return false;
  151.                 }
  152.  
  153.                 File.Delete(Path.Combine(filepath, filename));
  154.             }
  155.             return true;
  156.         }
  157.  
  158.         private static bool CheckForExampleFile(string filepath, string filename)
  159.         {
  160.             if (File.Exists(Path.Combine(filepath, filename)))
  161.                 return true;
  162.             return false;
  163.         }
  164.  
  165.     }
  166.  
  167.  
  168.     public struct ConfigFolders
  169.     {
  170.         public string BinFolder;
  171.         public string ConfigIncludeFolder;
  172.         public bool FoundResult;
  173.  
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement