summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-08-21 03:47:01 -0400
committerAdam <Adam@anope.org>2010-08-21 03:47:01 -0400
commit6608f16b7d3cc604b786b88eca2aad79e6b9b873 (patch)
treefa5bbd899d141f6d2e2e0b2a7f358aca16164322
parentfb551f0d5d412246a5221e8e9e310c191033b317 (diff)
Removed Config.bat and install.js and replaced it with a small C# program that tends to fail less.
-rw-r--r--Config.bat3
-rw-r--r--Config.exebin0 -> 9728 bytes
-rw-r--r--docs/WIN32.txt2
-rw-r--r--install.js304
-rw-r--r--src/win32/Config.cs204
5 files changed, 205 insertions, 308 deletions
diff --git a/Config.bat b/Config.bat
deleted file mode 100644
index eb320c09d..000000000
--- a/Config.bat
+++ /dev/null
@@ -1,3 +0,0 @@
-@echo off
-cscript /nologo "%~dp0\install.js"
-pause
diff --git a/Config.exe b/Config.exe
new file mode 100644
index 000000000..ccbe24c4c
--- /dev/null
+++ b/Config.exe
Binary files differ
diff --git a/docs/WIN32.txt b/docs/WIN32.txt
index 102c36702..1ebdc54fd 100644
--- a/docs/WIN32.txt
+++ b/docs/WIN32.txt
@@ -72,7 +72,7 @@ Anope for Windows
4) You now need to configure Anope to your requirements. At the prompt type:
- <path to source directory>\Config.bat
+ <path to source directory>\Config.exe
NOTE: If you run an Anti-Virus program such as McAfee or Norton, you may
be unable to run this command due to the protection in place. Some Anti-
diff --git a/install.js b/install.js
deleted file mode 100644
index 29ac86045..000000000
--- a/install.js
+++ /dev/null
@@ -1,304 +0,0 @@
-//
-// install.js - Windows Configuration
-//
-// (C) 2003-2010 Anope Team
-// Contact us at team@anope.org
-//
-// This program is free but copyrighted software; see the file COPYING for
-// details.
-//
-// Based on the original code of Epona by Lara.
-// Based on the original code of Services by Andy Church.
-//
-//
-
-var anopeVersion = "Unknown";
-var vMaj, vMin, vPat, vExtra;
-
-var installerResponses = new Array();
-
-var installerQuestions = [
- {
- 'question' : [
- 'In what directory do you want Anope to be installed?'
- ],
- 'short' : 'Install directory:',
- 'default_answer' : '',
- 'store_answer' : function(answer) {
- if (!answer)
- {
- WScript.Echo("You must give a directory!\n");
- return false;
- }
- if (!fso.FolderExists(answer))
- {
- if (fso.FileExists(answer))
- {
- WScript.Echo(answer + " exists, but is not a directory!\n");
- return false;
- }
- WScript.Echo(answer + " does not exist. Create it ([yes]/no)?\n");
- var inputValue = InstallerInput().toLowerCase();
- if (!inputValue)
- inputValue = 'yes';
- if (inputValue != 'no')
- fso.CreateFolder(answer);
- }
- else if (fso.FileExists(answer + '\\include\\services.h'))
- {
- WScript.Echo("You cannot use the Anope source directory as a target directory.\n");
- return false;
- }
- installerResponses['Install Directory'] = answer.replace(/\\/g, '/');
- return true;
- },
- 'cmake_argument' : function() {
- return '-DINSTDIR:STRING="' + installerResponses['Install Directory'] + '"';
- }
- },
- {
- 'question' : [
- 'Would you like to build using NMake instead of using Visual Studio?',
- 'NOTE: If you decide to use NMake, you must be in an environment where',
- ' NMake can function, such as the Visual Studio command line.',
- ' If you say yes to this while not in an environment that can run',
- ' NMake, it can cause the CMake configuration to enter an endless',
- ' loop.'
- ],
- 'short' : 'Use NMake?',
- 'options' : [
- 'yes',
- 'no'
- ],
- 'default_answer' : 'no',
- 'store_answer' : function(answer) {
- installerResponses['Use NMake'] = answer;
- return true;
- },
- 'cmake_argument' : function() {
- if (installerResponses['Use NMake'] == 'yes')
- return '-G"NMake Makefiles"';
- else
- return '';
- }
- },
- {
- 'question' : [
- 'Would you like to build a debug version of Anope?'
- ],
- 'short' : 'Build debug?',
- 'options' : [
- 'yes',
- 'no'
- ],
- 'default_answer' : 'no',
- 'store_answer' : function(answer) {
- installerResponses['Debug'] = answer;
- return true;
- },
- 'cmake_argument' : function() {
- if (installerResponses['Debug'] == 'msvc')
- return '';
- else if (installerResponses['Debug'] == 'yes')
- return '-DCMAKE_BUILD_TYPE:STRING=DEBUG';
- else
- return '-DCMAKE_BUILD_TYPE:STRING=RELEASE';
- }
- },
- {
- 'question' : [
- 'Are you using Visual Studio 2010? If you are, you need to answer yes',
- 'to this question, otherwise CMake will not function properly.'
- ],
- 'short' : 'Using Visual Studio 2010?',
- 'options' : [
- 'yes',
- 'no'
- ],
- 'default_answer' : 'no',
- 'store_answer' : function(answer) {
- installerResponses['Visual Studio 2010'] = answer;
- return true;
- },
- 'cmake_argument' : function() {
- if (installerResponses['Visual Studio 2010'] == 'yes')
- return '-G"Visual Studio 10"';
- else
- return '';
- }
- },
-];
-
-var bannerReplacements = [
- {
- 'findtext' : /CURVER/g,
- 'replacement' : function() { FindAnopeVersion(); return anopeVersion; }
- },
- {
- 'findtext' : / For more options type SOURCE_DIR\/Config --help/g,
- 'replacement' : function() { return ''; }
- }
-];
-
-var ScriptPath = WScript.ScriptFullName.substr(0, WScript.ScriptFullName.length - WScript.ScriptName.length);
-
-var fso = WScript.CreateObject('Scripting.FileSystemObject');
-var x, y, z;
-
-if (fso.FileExists(ScriptPath + '.BANNER'))
-{
- var bannerStream = fso.OpenTextFile(ScriptPath + '.BANNER');
- var bannerText = bannerStream.ReadAll();
- bannerStream.close();
-
- for (x in bannerReplacements)
- {
- var thisReplacement = bannerReplacements[x];
- bannerText = bannerText.replace(thisReplacement['findtext'], thisReplacement['replacement']);
- }
-
- WScript.Echo(bannerText + "\n");
-}
-else
- WScript.Echo("ERROR: Cannot find banner file!\n");
-
-WScript.Echo('Press Enter to Begin...');
-InstallerInput();
-WScript.Echo('');
-
-for (x in installerQuestions)
-{
- var thisQuestion = installerQuestions[x];
- var validResponse = false;
- var validOpts = new Array();
- if (thisQuestion.short == 'Build debug?' && installerResponses['Use NMake'] == 'no')
- {
- installerResponses['Debug'] = 'msvc';
- continue;
- }
- if (thisQuestion.short == 'Using Visual Studio 2010?' && installerResponses['Debug'] != 'msvc')
- {
- installerResponses['Visual Studio 2010'] = 'no';
- continue;
- }
- while (!validResponse)
- {
- for (y in thisQuestion.question)
- {
- var qLine = thisQuestion.question[y];
- WScript.Echo(qLine);
- }
- WScript.Echo('');
- var choiceLine = '';
- if (thisQuestion.options)
- {
- for (y in thisQuestion.options)
- {
- choiceLine += thisQuestion.options[y] + ', ';
- validOpts[thisQuestion.options[y]] = true;
- }
- choiceLine = choiceLine.substring(0, choiceLine.length - 2);
- WScript.Echo('Available Options: ' + choiceLine);
- }
- if (thisQuestion.default_answer)
- WScript.Echo('Default Answer: ' + thisQuestion.default_answer + "\n");
- WScript.Echo(thisQuestion.short);
- var inputValue = InstallerInput().toLowerCase();
- if (!inputValue)
- inputValue = thisQuestion.default_answer;
- if (choiceLine && !validOpts[inputValue])
- WScript.Echo("ERROR: Invalid option '" + inputValue + "'\n");
- else if (thisQuestion.store_answer(inputValue))
- validResponse = true;
- }
- WScript.Echo('');
-}
-
-WScript.Echo("\nAnope will be compiled with the following options:\n");
-for (x in installerResponses)
-{
- var thisResponse = installerResponses[x];
- WScript.Echo("\t" + x + ":\t\t[" + thisResponse.toUpperCase() + "]");
-}
-WScript.Echo("\tAnope Version:\t\t\t" + anopeVersion);
-WScript.Echo("\nTo continue, please press Enter...");
-InstallerInput();
-
-var cmake = 'cmake';
-for (x in installerQuestions)
-{
- var thisQuestion = installerQuestions[x];
- cmake += ' ' + thisQuestion.cmake_argument();
-}
-var fixedScriptPath = ScriptPath.replace(/\\/g, '/');
-cmake += ' "' + fixedScriptPath + '"';
-WScript.Echo(cmake + "\n");
-
-var shell = WScript.CreateObject('WScript.Shell');
-var cmake_shell = shell.exec('%comspec% /c ' + cmake);
-while (!cmake_shell.Status)
-{
- if (!cmake_shell.StdOut.AtEndOfStream)
- WScript.Echo(cmake_shell.StdOut.ReadLine());
- else if (!cmake_shell.StdErr.AtEndOfStream)
- WScript.Echo(cmake_shell.StdErr.ReadLine());
-}
-
-if (cmake_shell.ExitCode == 0)
-{
- if (installerResponses['Use NMake'] == 'yes') WScript.Echo("\nTo compile Anope, run 'nmake'. To install, run 'nmake install'.\n");
- else WScript.Echo("\nTo compile Anope, open Anope.sln and build the solution. To install,\ndo a build on the INSTALL project.\n");
- WScript.Echo("If you update Anope, you should run this script again to ensure\nall available options are set.\n");
-}
-else
- WScript.Echo("\nThere was an error attempting to run CMake! Check the above error message,\nand contact the Anope team if you are unsure how to proceed.\n");
-
-// -----------------------------------------------------------------
-
-// Functions
-
-function FindAnopeVersion() {
- if (!fso.FileExists(ScriptPath + 'src\\version.sh'))
- {
- anopeVersion = 'Unknown';
- return;
- }
-
- var versionLog = fso.OpenTextFile(ScriptPath + 'src\\version.sh');
- while (!versionLog.atEndOfStream)
- {
- var versionLine = versionLog.readline();
- var thisMatch = versionLine.replace('\n', '');
- while (thisMatch.match(/\"/g))
- thisMatch = thisMatch.replace('"', '');
- versionLine = thisMatch;
- if (versionLine.match(/VERSION_MAJOR=/g))
- {
- vMaj = versionLine.replace('VERSION_MAJOR=', '');
- continue;
- }
- if (versionLine.match(/VERSION_MINOR=/g))
- {
- vMin = versionLine.replace('VERSION_MINOR=', '');
- continue;
- }
- if (versionLine.match(/VERSION_PATCH=/g))
- {
- vPat = versionLine.replace('VERSION_PATCH=', '');
- continue;
- }
- if (versionLine.match(/VERSION_EXTRA=/g))
- {
- vExtra = versionLine.replace('VERSION_EXTRA=', '');
- continue;
- }
- }
- versionLog.close();
- anopeVersion = vMaj + '.' + vMin + '.' + vPat + vExtra;
- return;
-}
-
-function InstallerInput() {
- var input = WScript.StdIn.Readline();
- return input;
-}
diff --git a/src/win32/Config.cs b/src/win32/Config.cs
new file mode 100644
index 000000000..3c0547c1e
--- /dev/null
+++ b/src/win32/Config.cs
@@ -0,0 +1,204 @@
+/*
+ * Config.cs - Windows Configuration
+ *
+ * (C) 2003-2010 Anope Team
+ * Contact us at team@anope.org
+ *
+ * This program is free but copyrighted software; see the file COPYING for
+ * details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ *
+ * Written by Scott <stealtharcher.scott@gmail.com>
+ * Written by Adam <Adam@anope.org>
+ *
+ * Compile with: csc /out:Config.exe Config.cs
+ *
+ */
+
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+
+namespace Config
+{
+ class Config
+ {
+ static string InstallDirectory;
+ static bool UseNMake, BuildDebug;
+
+ static bool CheckResponse(string InstallerResponse)
+ {
+ if (System.String.Compare(InstallerResponse, "yes", true) == 0 || System.String.Compare(InstallerResponse, "y", true) == 0)
+ return true;
+ return false;
+ }
+
+ static string FindAnopeVersion()
+ {
+ if (!File.Exists(@"src\version.sh"))
+ return "Unknown";
+
+ Dictionary<string, string> versions = new Dictionary<string, string>();
+ string[] versionfile = File.ReadAllLines(@"src\version.sh");
+ foreach (string line in versionfile)
+ {
+ if (line.StartsWith("VERSION_"))
+ {
+ string key = line.Split('_')[1].Split('=')[0];
+ if (!versions.ContainsKey(key))
+ {
+ versions.Add(key, line.Split('=')[1].Replace("\"", "").Replace("\'", ""));
+ }
+ }
+ }
+
+ try
+ {
+ if (versions.ContainsKey("BUILD"))
+ return string.Format("{0}.{1}.{2}.{3}{4}", versions["MAJOR"], versions["MINOR"], versions["PATCH"], versions["BUILD"], versions["EXTRA"]);
+ else
+ return string.Format("{0}.{1}.{2}{3}", versions["MAJOR"], versions["MINOR"], versions["PATCH"], versions["EXTRA"]);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ return "Unknown";
+ }
+ }
+
+ static void RunCMake(string cMake)
+ {
+ try
+ {
+ ProcessStartInfo processStartInfo = new ProcessStartInfo("cmake")
+ {
+ RedirectStandardError = true,
+ RedirectStandardOutput = true,
+ UseShellExecute = false,
+ Arguments = cMake
+ };
+ Process pCMake = Process.Start(processStartInfo);
+ StreamReader stdout = pCMake.StandardOutput;
+ StreamReader stderr = pCMake.StandardError;
+ string stdoutr, stderrr;
+ List<string> errors = new List<string>();
+ while (!pCMake.HasExited)
+ {
+ if ((stdoutr = stdout.ReadLine()) != null)
+ Console.WriteLine(stdoutr);
+ if ((stderrr = stderr.ReadLine()) != null)
+ errors.Add(stderrr);
+ }
+ foreach (string error in errors)
+ {
+ Console.WriteLine(error);
+ }
+ Console.WriteLine("");
+ if (pCMake.ExitCode == 0)
+ {
+ if (UseNMake)
+ Console.WriteLine("To compile Anope, run 'nmake'. To install, run 'nmake install'");
+ else
+ Console.WriteLine("To compile Anope, open Anope.sln and build the solution. To install, do a build on the INSTALL project");
+ }
+ else
+ Console.WriteLine("There was an error attempting to run CMake! Check the above error message, and contact the Anope team if you are unsure how to proceed.");
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("");
+ Console.WriteLine(DateTime.UtcNow + " UTC: " + e.Message);
+ Console.WriteLine("There was an error attempting to run CMake! Check the above error message, and contact the Anope team if you are unsure how to proceed.");
+ }
+ }
+
+ static int Main()
+ {
+ string AnopeVersion = FindAnopeVersion();
+
+ if (File.Exists(".BANNER"))
+ Console.WriteLine(File.ReadAllText(".BANNER").Replace("CURVER", AnopeVersion).Replace("For more options type SOURCE_DIR/Config --help", ""));
+
+ Console.WriteLine("Press Enter to begin");
+ Console.WriteLine("");
+ Console.ReadKey();
+
+ Dictionary<int, string> InstallerQuestions = new Dictionary<int, string>();
+ InstallerQuestions.Add(0, "Where do you want Anope to be installed?");
+ InstallerQuestions.Add(1, "Would you like to build using NMake instead of using Visual Studio?\r\nNOTE: If you decide to use NMake, you must be in an environment where\r\nNMake can function, such as the Visual Studio command line. If you say\r\nyes to this while not in an environment that can run NMake, it can\r\ncause the CMake configuration to enter an endless loop. [y/n]");
+ InstallerQuestions.Add(2, "Would you like to build a debug version of Anope? [y/n]");
+
+ for (int i = 0; i < InstallerQuestions.Count; ++i)
+ {
+ Console.WriteLine(InstallerQuestions[i]);
+ string InstallerResponse = Console.ReadLine();
+ Console.WriteLine("");
+
+ if (InstallerResponse == null || InstallerResponse.Length < 1)
+ {
+ Console.WriteLine("Invlaid option");
+ --i;
+ continue;
+ }
+
+ switch (i)
+ {
+ case 0:
+ if (!Directory.Exists(InstallerResponse))
+ {
+ Console.WriteLine("Directory does not exist! Creating directory.");
+ Console.WriteLine("");
+ try
+ {
+ Directory.CreateDirectory(InstallerResponse);
+ InstallDirectory = InstallerResponse;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Unable to create directory: " + e.Message);
+ --i;
+ }
+ }
+ else if (File.Exists(InstallerResponse + @"\include\services.h"))
+ {
+ Console.WriteLine("You cannot use the Anope source directory as the target directory!");
+ --i;
+ }
+ else
+ InstallDirectory = InstallerResponse;
+ break;
+ case 1:
+ UseNMake = CheckResponse(InstallerResponse);
+ break;
+ case 2:
+ BuildDebug = CheckResponse(InstallerResponse);
+ break;
+ default:
+ break;
+ }
+ }
+
+ Console.WriteLine("Anope will be compiled with the following options:");
+ Console.WriteLine("Install directory: {0}", InstallDirectory);
+ Console.WriteLine("Use NMake: {0}", UseNMake ? "Yes" : "No");
+ Console.WriteLine("Using Visual Studio 2010: {0}", !UseNMake ? "Yes" : "No");
+ Console.WriteLine("Build debug: {0}", BuildDebug ? "Yes" : "No");
+ Console.WriteLine("Anope Version: {0}", AnopeVersion); ;
+ Console.WriteLine("Press Enter to continue...");
+ Console.ReadKey();
+ InstallDirectory = "-DINSTDIR:STRING=\"" + InstallDirectory.Replace('\\', '/') + "\" ";
+ string NMake = UseNMake ? "-G\"NMake Makefiles\" " : "";
+ string Debug = BuildDebug ? "-DCMAKE_BUILD_TYPE:STRING=DEBUG " : "-DCMAKE_BUILD_TYPE:STRING=RELEASE ";
+ string VisualStudio = !UseNMake ? "-G\"Visual Studio 10\" " : "";
+ string cMake = InstallDirectory + NMake + Debug + VisualStudio + Environment.CurrentDirectory.Replace('\\','/');
+ RunCMake(cMake);
+
+ return 0;
+ }
+ }
+}
+