Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(
- "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");
- Console.Write("\nWould you like to Continue? y/n[y]:");
- ConsoleKeyInfo keyResult = Console.ReadKey();
- if (keyResult.Key == ConsoleKey.N)
- return;
- ConfigFolders folders = GetConfigFolders();
- if (!folders.FoundResult)
- {
- 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");
- //readresult = Console.ReadKey();
- keyResult = Console.ReadKey();
- return;
- }
- // Check for example files
- if (!CheckForExampleFile(folders.BinFolder,"OpenSim.ini.example"))
- {
- 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");
- keyResult = Console.ReadKey();
- return;
- }
- if (!CheckForExampleFile(folders.ConfigIncludeFolder, "StandaloneCommon.ini.example"))
- {
- 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");
- keyResult = Console.ReadKey();
- return;
- }
- // Check to see if the config files already exist so we don't overwrite them.
- if (!CheckForAndRemoveFile(folders.BinFolder,"OpenSim.ini"))
- {
- return;
- }
- if (!CheckForAndRemoveFile(folders.ConfigIncludeFolder, "StandaloneCommon.ini"))
- {
- return;
- }
- // Copy the example files into the destination.
- try
- {
- File.Copy(Path.Combine(folders.BinFolder, "OpenSim.ini.example"),
- Path.Combine(folders.BinFolder, "OpenSim.ini"));
- }
- catch (Exception)
- {
- Console.WriteLine("\nThere was a problem copying OpenSim.ini.example. This is usually a permissions problem. \n\nThis program will now exit.\n");
- keyResult = Console.ReadKey();
- return;
- }
- try
- {
- File.Copy(Path.Combine(folders.ConfigIncludeFolder, "StandaloneCommon.ini.example"),
- Path.Combine(folders.ConfigIncludeFolder, "StandaloneCommon.ini"));
- }
- catch (Exception)
- {
- Console.WriteLine("\nThere was a problem copying StandaloneCommon.ini.example. This is usually a permissions problem. \n\nThis program will now exit.\n");
- keyResult = Console.ReadKey();
- return;
- }
- try
- {
- // Append the standalone architecture line
- StreamWriter sw = File.AppendText(Path.Combine(folders.BinFolder, "OpenSim.ini"));
- sw.WriteLine("Include-Architecture = \"config-include/Standalone.ini\"");
- sw.Flush();
- sw.Close();
- sw.Dispose();
- }
- catch (Exception)
- {
- Console.WriteLine("\nThere was a problem appending to OpenSim.ini. This is usually a permissions problem. \n\nThis program will now exit.\n");
- keyResult = Console.ReadKey();
- return;
- }
- Console.WriteLine("\n\nOK, All Succeeded. Next, Compile OpenSimulator if you have not already and run OpenSim.exe");
- keyResult = Console.ReadKey();
- }
- private static ConfigFolders GetConfigFolders()
- {
- string lBinFolder = ".";
- string lConfigIncludeFolder = ".";
- string lCurrentDirectory = ".";
- if (File.Exists(Path.Combine(lCurrentDirectory,"prebuild.xml")) && Directory.Exists(Path.Combine(".","bin")))
- {
- // We're in the regular OpenSim directory
- lBinFolder = Path.Combine(".","bin");
- lConfigIncludeFolder = Path.Combine(Path.Combine(".","bin"), "config-include");
- lCurrentDirectory = ".";
- ConfigFolders retFolders = new ConfigFolders(){BinFolder = lBinFolder,ConfigIncludeFolder=lConfigIncludeFolder,FoundResult=true};
- return retFolders;
- }
- if (Directory.Exists(Path.Combine(".","config-include")))
- {
- lBinFolder = ".";
- lConfigIncludeFolder = Path.Combine(".","config-include");
- ConfigFolders retFolders = new ConfigFolders() { BinFolder = lBinFolder, ConfigIncludeFolder = lConfigIncludeFolder, FoundResult = true };
- return retFolders;
- }
- ConfigFolders gretFolders = new ConfigFolders();
- return gretFolders;
- }
- private static bool CheckForAndRemoveFile(string filepath,string filename)
- {
- ConsoleKeyInfo keyResult;
- if (File.Exists(Path.Combine(filepath, filename)))
- {
- Console.WriteLine(String.Format("\n WARNING: {0} already exists.",filename));
- Console.Write("Would you like to overwrite it? y/n[n]:");
- keyResult = Console.ReadKey();
- if (keyResult.Key != ConsoleKey.Y)
- {
- Console.WriteLine("This program will now exit.\n");
- keyResult = Console.ReadKey();
- return false;
- }
- File.Delete(Path.Combine(filepath, filename));
- }
- return true;
- }
- private static bool CheckForExampleFile(string filepath, string filename)
- {
- if (File.Exists(Path.Combine(filepath, filename)))
- return true;
- return false;
- }
- }
- public struct ConfigFolders
- {
- public string BinFolder;
- public string ConfigIncludeFolder;
- public bool FoundResult;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement