diff --git a/Makefile b/Makefile index 82f6d1facf..9d381cc05d 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,6 @@ # to compile, run: # make [DEBUG=false] # -# to compile with development tools, run: -# make all [DEBUG=false] -# # to check unit tests (requires NUnit version >= 2.6), run: # make nunit [NUNIT_CONSOLE=] [NUNIT_LIBS_PATH=] [NUNIT_LIBS=] # Use NUNIT_CONSOLE if nunit[3|2]-console was not downloaded by `make dependencies` nor is it in bin search paths @@ -23,9 +20,6 @@ # to install, run: # make [prefix=/foo] [bindir=/bar/bin] install # -# to install with development tools, run: -# make [prefix=/foo] [bindir=/bar/bin] install-all -# # to install Linux startup scripts, desktop files and icons: # make install-linux-shortcuts [DEBUG=false] # @@ -88,7 +82,6 @@ INSTALL_DATA = $(INSTALL) -m644 # program targets CORE = pdefault game utility server -TOOLS = gamemonitor VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || echo git-`git rev-parse --short HEAD`) # dependencies @@ -109,7 +102,6 @@ game_SRCS := $(shell find OpenRA.Game/ -iname '*.cs') game_TARGET = OpenRA.Game.exe game_KIND = winexe game_LIBS = $(COMMON_LIBS) $(game_DEPS) thirdparty/download/SharpFont.dll thirdparty/download/Open.Nat.dll -game_FLAGS = -win32icon:OpenRA.Game/OpenRA.ico PROGRAMS += game game: $(game_TARGET) @@ -181,9 +173,6 @@ check: utility mods @echo "Checking for code style violations in OpenRA.Platforms.Default..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Platforms.Default @echo - @echo "Checking for code style violations in OpenRA.GameMonitor..." - @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.GameMonitor - @echo @echo "Checking for code style violations in OpenRA.Mods.Common..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.Common @echo @@ -238,16 +227,6 @@ test: utility mods ##### Launchers / Utilities ##### -gamemonitor_SRCS := $(shell find OpenRA.GameMonitor/ -iname '*.cs') -gamemonitor_TARGET = OpenRA.exe -gamemonitor_KIND = winexe -gamemonitor_DEPS = $(game_TARGET) -gamemonitor_LIBS = $(COMMON_LIBS) $(gamemonitor_DEPS) System.Windows.Forms.dll -gamemonitor_FLAGS = -win32icon:OpenRA.Game/OpenRA.ico -PROGRAMS += gamemonitor -gamemonitor: $(gamemonitor_TARGET) - -# Backend for the launcher apps - queries game/mod info and applies actions to an install utility_SRCS := $(shell find OpenRA.Utility/ -iname '*.cs') utility_TARGET = OpenRA.Utility.exe utility_KIND = exe @@ -297,13 +276,11 @@ default: core core: dependencies game platforms mods utility server -tools: gamemonitor - -package: all-dependencies core tools docs version +package: all-dependencies core docs version mods: mod_common mod_cnc mod_d2k -all: dependencies core tools +all: dependencies core clean: @-$(RM_F) *.exe *.dll *.dylib *.dll.config ./OpenRA*/*.dll ./OpenRA*/*.mdb *.mdb mods/**/*.dll mods/**/*.mdb *.resources @@ -353,8 +330,6 @@ man-page: utility mods install: install-core -install-all: install-core install-tools - install-linux-shortcuts: install-linux-scripts install-linux-icons install-linux-desktop install-core: default @@ -393,11 +368,6 @@ ifneq ($(UNAME_S),Darwin) @$(CP) *.sh "$(DATA_INSTALL_DIR)" endif -install-tools: tools - @-echo "Installing OpenRA tools to $(DATA_INSTALL_DIR)" - @$(INSTALL_DIR) "$(DATA_INSTALL_DIR)" - @$(INSTALL_PROGRAM) $(foreach prog,$(TOOLS),$($(prog)_TARGET)) "$(DATA_INSTALL_DIR)" - install-linux-icons: @$(INSTALL_DIR) "$(DESTDIR)$(datadir)/icons/" @$(CP_R) packaging/linux/hicolor "$(DESTDIR)$(datadir)/icons/" @@ -476,9 +446,6 @@ help: @echo 'to compile, run:' @echo ' make [DEBUG=false]' @echo - @echo 'to compile with development tools, run:' - @echo ' make all [DEBUG=false]' - @echo @echo 'to check unit tests (requires NUnit version >= 2.6), run:' @echo ' make nunit [NUNIT_CONSOLE=] [NUNIT_LIBS_PATH=] [NUNIT_LIBS=]' @echo ' Use NUNIT_CONSOLE if nunit[3|2]-console was not downloaded by `make dependencies` nor is it in bin search paths' @@ -494,9 +461,6 @@ help: @echo 'to install, run:' @echo ' make [prefix=/foo] [bindir=/bar/bin] install' @echo - @echo 'to install with development tools, run:' - @echo ' make [prefix=/foo] [bindir=/bar/bin] install-all' - @echo @echo 'to install Linux startup scripts, desktop files and icons' @echo ' make install-linux-shortcuts [DEBUG=false]' @echo @@ -515,4 +479,4 @@ help: .SUFFIXES: -.PHONY: core tools package all mods clean distclean dependencies version $(PROGRAMS) nunit +.PHONY: core package all mods clean distclean dependencies version $(PROGRAMS) nunit diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 1cc6d5c814..e02b9ba75e 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -16,7 +16,6 @@ false - OpenRA.ico publish\ true Disk @@ -352,8 +351,5 @@ false - - - diff --git a/OpenRA.Game/OpenRA.ico b/OpenRA.Game/OpenRA.ico deleted file mode 100644 index f503a3b7c1..0000000000 Binary files a/OpenRA.Game/OpenRA.ico and /dev/null differ diff --git a/OpenRA.GameMonitor/GameMonitor.cs b/OpenRA.GameMonitor/GameMonitor.cs deleted file mode 100644 index d153ee6737..0000000000 --- a/OpenRA.GameMonitor/GameMonitor.cs +++ /dev/null @@ -1,155 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Media; -using System.Reflection; -using System.Windows.Forms; - -namespace OpenRA -{ - class GameMonitor - { - static Process gameProcess; - - [STAThread] - static void Main(string[] args) - { - var launcherPath = Assembly.GetExecutingAssembly().Location; - var directory = Path.GetDirectoryName(launcherPath); - var enginePath = Path.Combine(directory, "OpenRA.Game.exe"); - - Directory.SetCurrentDirectory(directory); - - var engineArgs = args - .Append("Engine.LaunchPath=" + launcherPath) - .Select(arg => "\"" + arg + "\""); - - var psi = new ProcessStartInfo(enginePath, string.Join(" ", engineArgs)); - - try - { - gameProcess = Process.Start(psi); - } - catch - { - return; - } - - if (gameProcess == null) - return; - - gameProcess.EnableRaisingEvents = true; - gameProcess.Exited += GameProcessExited; - - Application.Run(); - } - - static void ShowErrorDialog() - { - var form = new Form - { - Size = new Size(315, 140), - Text = "Fatal Error", - MinimizeBox = false, - MaximizeBox = false, - FormBorderStyle = FormBorderStyle.FixedDialog, - StartPosition = FormStartPosition.CenterScreen, - TopLevel = true, - Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location) - }; - - var notice = new Label - { - Location = new Point(10, 10), - AutoSize = true, - Text = "OpenRA has encountered a fatal error and must close.{0}Refer to the crash logs and FAQ for more information.".F(Environment.NewLine), - TextAlign = ContentAlignment.TopCenter - }; - - var viewLogs = new Button - { - Location = new Point(10, 80), - Size = new Size(75, 23), - Text = "View Logs" - }; - - var viewFaq = new Button - { - Location = new Point(90, 80), - Size = new Size(75, 23), - Text = "View FAQ" - }; - - var quit = new Button - { - Location = new Point(225, 80), - Size = new Size(75, 23), - Text = "Quit", - DialogResult = DialogResult.Cancel - }; - - form.Controls.Add(notice); - form.Controls.Add(viewLogs); - form.Controls.Add(viewFaq); - form.Controls.Add(quit); - - viewLogs.Click += ViewLogsClicked; - viewFaq.Click += ViewFaqClicked; - form.FormClosed += FormClosed; - - SystemSounds.Exclamation.Play(); - form.ShowDialog(); - } - - static void GameProcessExited(object sender, EventArgs e) - { - if (gameProcess.ExitCode != (int)RunStatus.Success) - ShowErrorDialog(); - - Exit(); - } - - static void ViewLogsClicked(object sender, EventArgs e) - { - try - { - Process.Start(Platform.ResolvePath("^", "Logs")); - } - catch - { } - } - - static void ViewFaqClicked(object sender, EventArgs e) - { - try - { - Process.Start("http://wiki.openra.net/FAQ"); - } - catch - { } - } - - static void FormClosed(object sender, EventArgs e) - { - Exit(); - } - - static void Exit() - { - Environment.Exit(0); - } - } -} diff --git a/OpenRA.GameMonitor/OpenRA.GameMonitor.csproj b/OpenRA.GameMonitor/OpenRA.GameMonitor.csproj deleted file mode 100644 index f2a1398538..0000000000 --- a/OpenRA.GameMonitor/OpenRA.GameMonitor.csproj +++ /dev/null @@ -1,54 +0,0 @@ - - - - Debug - x86 - {68295755-7902-4602-AC2C-9A8AC36D5EF7} - WinExe - OpenRA - OpenRA - v4.5 - - - true - full - ..\ - DEBUG;TRACE - prompt - x86 - AllRules.ruleset - true - false - - - ..\OpenRA.Game\OpenRA.ico - - - true - ..\ - TRACE - true - pdbonly - x86 - false - prompt - AllRules.ruleset - true - - - - - - - - - {0DFB103F-2962-400F-8C6D-E2C28CCBA633} - OpenRA.Game - False - - - - - - - \ No newline at end of file diff --git a/OpenRA.sln b/OpenRA.sln index 8561232bb2..ea62892b62 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -131,8 +131,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "System Lua scripts", "Syste lua\stacktraceplus.lua = lua\stacktraceplus.lua EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.GameMonitor", "OpenRA.GameMonitor\OpenRA.GameMonitor.csproj", "{68295755-7902-4602-AC2C-9A8AC36D5EF7}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Test", "OpenRA.Test\OpenRA.Test.csproj", "{6CB8E1B7-6B36-4D93-8633-7C573E194AC4}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tiberian Sun Lua scripts", "Tiberian Sun Lua scripts", "{85159569-F5BD-458E-B5C0-EB16690C432B}" diff --git a/appveyor.yml b/appveyor.yml index 456db769d7..36d6d88022 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -53,7 +53,9 @@ after_test: - appveyor DownloadFile "https://raw.githubusercontent.com/wiki/OpenRA/OpenRA/Changelog.md" -FileName Changelog.md - make docs - ps: dir *.md | % {gc $_ -Raw | .\ConvertFrom-Markdown.ps1 | Out-File -FilePath "$($_.Name.TrimEnd(".md")).html"} - - ps: cp OpenRA.Game/OpenRA.ico . + - ps: (Get-Content "${env:APPVEYOR_BUILD_FOLDER}\packaging\windows\WindowsLauncher.cs.in").replace('DISPLAY_NAME', 'OpenRA').replace('MOD_ID', '').replace('FAQ_URL', 'http://wiki.openra.net/FAQ') | Set-Content "${env:APPVEYOR_BUILD_FOLDER}\packaging\windows\WindowsLauncher.cs" + - ps: csc.exe /noconfig /platform:x86 /reference:System.dll /reference:System.Core.dll /reference:System.Drawing.dll /reference:System.Windows.Forms.dll /reference:"${env:APPVEYOR_BUILD_FOLDER}\OpenRA.Game.exe" /out:"${env:APPVEYOR_BUILD_FOLDER}\OpenRA.exe" /win32icon:"${env:APPVEYOR_BUILD_FOLDER}\packaging\windows\OpenRA.ico" /target:winexe ${env:APPVEYOR_BUILD_FOLDER}\packaging\windows\WindowsLauncher.cs + - ps: cp packaging\windows\OpenRA.ico . - '"C:\Program Files (x86)\NSIS\makensis.exe" /DSRCDIR="%APPVEYOR_BUILD_FOLDER%" /DDEPSDIR="%APPVEYOR_BUILD_FOLDER%\thirdparty\download\windows" /V3 packaging/windows/OpenRA.nsi' - if defined APPVEYOR_REPO_TAG_NAME set VERSION=%APPVEYOR_REPO_TAG_NAME% - if not defined APPVEYOR_REPO_TAG_NAME set VERSION=%APPVEYOR_REPO_COMMIT:~0,7% diff --git a/packaging/package-all.sh b/packaging/package-all.sh index 5261da70e2..84ed6591ac 100755 --- a/packaging/package-all.sh +++ b/packaging/package-all.sh @@ -70,10 +70,7 @@ cp thirdparty/download/MaxMind.Db.dll packaging/built cp thirdparty/download/SmarIrc4net.dll packaging/built # Copy game icon for windows package -cp OpenRA.Game/OpenRA.ico packaging/built - -# Copy the Windows crash monitor -cp OpenRA.exe packaging/built +cp packaging/windows/OpenRA.ico packaging/built cd packaging echo "Creating packages..." diff --git a/packaging/windows/OpenRA.ico b/packaging/windows/OpenRA.ico new file mode 100644 index 0000000000..0f65e21d36 Binary files /dev/null and b/packaging/windows/OpenRA.ico differ diff --git a/packaging/windows/WindowsLauncher.cs.in b/packaging/windows/WindowsLauncher.cs.in new file mode 100644 index 0000000000..b9d6096334 --- /dev/null +++ b/packaging/windows/WindowsLauncher.cs.in @@ -0,0 +1,232 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Media; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace OpenRA +{ + class WindowsLauncher + { + [DllImport("user32.dll")] + static extern int SendMessage(IntPtr hwnd, uint message, uint wParam, IntPtr lParam); + + [DllImport("shell32.dll")] + static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); + + [DllImport("user32.dll")] + public extern static bool DestroyIcon(IntPtr handle); + + struct SHFILEINFO + { + // Native type: HICON + public IntPtr hIcon; + + public int iIcon; + public uint dwAttributes; + + // Native type: TCHAR[MAX_PATH] + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + + public string szDisplayName; + + // Native type: TCHAR[80] + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] + + public string szTypeName; + } + + static Process gameProcess; + + // Constants to be replaced by the wrapper / compilation script + const string ModID = "MOD_ID"; + const string DisplayName = "DISPLAY_NAME"; + const string FaqUrl = "FAQ_URL"; + + // References to the OpenRA.Game.exe icons for later cleanup + static IntPtr[] iconHandle = { IntPtr.Zero, IntPtr.Zero }; + + [STAThread] + static void Main(string[] args) + { + var launcherPath = Assembly.GetExecutingAssembly().Location; + var directory = Path.GetDirectoryName(launcherPath); + var enginePath = Path.Combine(directory, "OpenRA.Game.exe"); + + Directory.SetCurrentDirectory(directory); + + if (!string.IsNullOrEmpty(ModID)) + args = args.Append("Game.Mod=" + ModID).ToArray(); + + var engineArgs = args + .Append("Engine.LaunchPath=" + launcherPath) + .Select(arg => "\"" + arg + "\""); + + var psi = new ProcessStartInfo(enginePath, string.Join(" ", engineArgs)); + + try + { + gameProcess = Process.Start(psi); + } + catch + { + return; + } + + if (gameProcess == null) + return; + + if (Platform.CurrentPlatform == PlatformType.Windows) + { + // Set the OpenRA.Game.exe icon to match the mod + // Icon.ExtractAssociatedIcon sets only the 32px icon, + // so we use native functions to set both 16 and 32px versions. + gameProcess.WaitForInputIdle(); + SHFILEINFO sfi = new SHFILEINFO(); + for (var i = 0; i < 2; i++) + { + SHGetFileInfo(Assembly.GetExecutingAssembly().Location, 0, ref sfi, (uint)Marshal.SizeOf(sfi), (uint)(0x100 + i)); + iconHandle[i] = sfi.hIcon; + SendMessage(gameProcess.MainWindowHandle, 0x80, (uint)(1 - i), sfi.hIcon); + } + } + + gameProcess.EnableRaisingEvents = true; + gameProcess.Exited += GameProcessExited; + + Application.Run(); + } + + static void ShowErrorDialog() + { + var headerLabel = new Label + { + Location = new Point(0, 10), + Height = 15, + Text = DisplayName + " has encountered a fatal error and must close.", + TextAlign = ContentAlignment.TopCenter + }; + + var docsLabel = new Label + { + Location = new Point(0, 25), + Height = 15, + Text = "Refer to the crash logs and FAQ for more information.", + TextAlign = ContentAlignment.TopCenter + }; + + int formWidth; + using (var g = headerLabel.CreateGraphics()) + { + var headerWidth = (int)g.MeasureString(headerLabel.Text, headerLabel.Font).Width + 60; + var docsWidth = (int)g.MeasureString(docsLabel.Text, docsLabel.Font).Width + 60; + formWidth = Math.Max(headerWidth, docsWidth); + headerLabel.Width = formWidth; + docsLabel.Width = formWidth; + } + + var form = new Form + { + Size = new Size(formWidth, 110), + Text = "Fatal Error", + MinimizeBox = false, + MaximizeBox = false, + FormBorderStyle = FormBorderStyle.FixedDialog, + StartPosition = FormStartPosition.CenterScreen, + TopLevel = true, + Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location) + }; + + var viewLogs = new Button + { + Location = new Point(10, 50), + Size = new Size(75, 23), + Text = "View Logs" + }; + + var viewFaq = new Button + { + Location = new Point(90, 50), + Size = new Size(75, 23), + Text = "View FAQ" + }; + + var quit = new Button + { + Location = new Point(formWidth - 90, 50), + Size = new Size(75, 23), + Text = "Quit", + DialogResult = DialogResult.Cancel + }; + + form.Controls.Add(headerLabel); + form.Controls.Add(docsLabel); + form.Controls.Add(viewLogs); + form.Controls.Add(viewFaq); + form.Controls.Add(quit); + + viewLogs.Click += ViewLogsClicked; + viewFaq.Click += ViewFaqClicked; + form.FormClosed += FormClosed; + + SystemSounds.Exclamation.Play(); + form.ShowDialog(); + } + + static void GameProcessExited(object sender, EventArgs e) + { + if (gameProcess.ExitCode != (int)RunStatus.Success) + ShowErrorDialog(); + + if (Platform.CurrentPlatform == PlatformType.Windows) + foreach (var handle in iconHandle) + if (handle != IntPtr.Zero) + DestroyIcon(handle); + + Exit(); + } + + static void ViewLogsClicked(object sender, EventArgs e) + { + try + { + Process.Start(Platform.ResolvePath("^", "Logs")); + } + catch { } + } + + static void ViewFaqClicked(object sender, EventArgs e) + { + try + { + Process.Start(FaqUrl); + } + catch { } + } + + static void FormClosed(object sender, EventArgs e) + { + Exit(); + } + + static void Exit() + { + Environment.Exit(0); + } + } +} diff --git a/packaging/windows/buildpackage.sh b/packaging/windows/buildpackage.sh index 6b6987f0c1..eff2d76566 100755 --- a/packaging/windows/buildpackage.sh +++ b/packaging/windows/buildpackage.sh @@ -5,6 +5,20 @@ BUILTDIR="$2" SRCDIR="$3" OUTPUTDIR="$4" +LAUNCHER_LIBS="-r:System.dll -r:System.Drawing.dll -r:System.Windows.Forms.dll -r:${BUILTDIR}/OpenRA.Game.exe" +FAQ_URL="http://wiki.openra.net/FAQ" + +function makelauncher() +{ + sed "s|DISPLAY_NAME|$2|" WindowsLauncher.cs.in | sed "s|MOD_ID|$3|" | sed "s|FAQ_URL|${FAQ_URL}|" > WindowsLauncher.cs + mcs -sdk:4.5 WindowsLauncher.cs -warn:4 -codepage:utf8 -warnaserror -out:"$1" -t:winexe ${LAUNCHER_LIBS} -win32icon:"$4" + rm WindowsLauncher.cs + mono ${SRCDIR}/fixheader.exe $1 > /dev/null +} + +echo "Compiling Windows launcher" +makelauncher ${BUILTDIR}/OpenRA.exe "OpenRA" "" OpenRA.ico + if [ -x /usr/bin/makensis ]; then echo "Building Windows setup.exe" makensis -V2 -DSRCDIR="$BUILTDIR" -DDEPSDIR="${SRCDIR}/thirdparty/download/windows" OpenRA.nsi