Move Platform.cs to OpenRA.FileFormats, fix #765.
This commit is contained in:
committed by
Chris Forbes
parent
608126483e
commit
20458fc552
@@ -19,7 +19,6 @@ namespace OpenRA.FileFormats
|
||||
public static class FileSystem
|
||||
{
|
||||
static List<IFolder> mountedFolders = new List<IFolder>();
|
||||
public static string SupportDir = "."; // Default to "current dir" if we aren't told otherwise
|
||||
|
||||
static Cache<uint, List<IFolder>> allFiles = new Cache<uint, List<IFolder>>( _ => new List<IFolder>() );
|
||||
|
||||
@@ -77,7 +76,7 @@ namespace OpenRA.FileFormats
|
||||
|
||||
// paths starting with ^ are relative to the support dir
|
||||
if (name.StartsWith("^"))
|
||||
name = FileSystem.SupportDir+name.Substring(1);
|
||||
name = Platform.SupportDir+name.Substring(1);
|
||||
|
||||
var a = (Action)(() => FileSystem.MountInner(OpenPackage(name)));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -75,6 +75,7 @@
|
||||
<Compile Include="Mod.cs" />
|
||||
<Compile Include="PackageEntry.cs" />
|
||||
<Compile Include="Palette.cs" />
|
||||
<Compile Include="Platform.cs" />
|
||||
<Compile Include="PlayerColorRemap.cs" />
|
||||
<Compile Include="Primitives\ActionQueue.cs" />
|
||||
<Compile Include="Primitives\DisposableAction.cs" />
|
||||
|
||||
84
OpenRA.FileFormats/Platform.cs
Normal file
84
OpenRA.FileFormats/Platform.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public enum PlatformType
|
||||
{
|
||||
Unknown,
|
||||
Windows,
|
||||
OSX,
|
||||
Linux
|
||||
}
|
||||
|
||||
public static class Platform
|
||||
{
|
||||
public static PlatformType CurrentPlatform
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentPlatform.Value;
|
||||
}
|
||||
}
|
||||
|
||||
static Lazy<PlatformType> currentPlatform = new Lazy<PlatformType>(GetCurrentPlatform);
|
||||
|
||||
static PlatformType GetCurrentPlatform()
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) return PlatformType.Windows;
|
||||
|
||||
try
|
||||
{
|
||||
var psi = new ProcessStartInfo("uname", "-s");
|
||||
psi.UseShellExecute = false;
|
||||
psi.RedirectStandardOutput = true;
|
||||
var p = Process.Start(psi);
|
||||
var kernelName = p.StandardOutput.ReadToEnd();
|
||||
if (kernelName.Contains("Linux") || kernelName.Contains("BSD"))
|
||||
return PlatformType.Linux;
|
||||
if (kernelName.Contains("Darwin"))
|
||||
return PlatformType.OSX;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return PlatformType.Unknown;
|
||||
}
|
||||
|
||||
public static string SupportDir
|
||||
{
|
||||
get
|
||||
{
|
||||
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
switch (CurrentPlatform)
|
||||
{
|
||||
case PlatformType.OSX:
|
||||
dir += "/Library/Application Support/OpenRA";
|
||||
break;
|
||||
case PlatformType.Linux:
|
||||
dir += "/.openra";
|
||||
break;
|
||||
default:
|
||||
dir += Path.DirectorySeparatorChar + "OpenRA";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
return dir + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA
|
||||
|
||||
public static Renderer Renderer;
|
||||
public static bool HasInputFocus = false;
|
||||
|
||||
|
||||
public static void MoveViewport(float2 loc)
|
||||
{
|
||||
viewport.Center(loc);
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA
|
||||
public static void JoinServer(string host, int port)
|
||||
{
|
||||
var replayFilename = ChooseReplayFilename();
|
||||
string path = Path.Combine( Game.SupportDir, "Replays" );
|
||||
string path = Path.Combine( Platform.SupportDir, "Replays" );
|
||||
if( !Directory.Exists( path ) ) Directory.CreateDirectory( path );
|
||||
var replayFile = File.Create( Path.Combine( path, replayFilename ) );
|
||||
|
||||
@@ -223,18 +223,12 @@ namespace OpenRA
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
|
||||
|
||||
var defaultSupport = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
||||
+ Path.DirectorySeparatorChar + "OpenRA";
|
||||
|
||||
SupportDir = args.GetValue("SupportDir", defaultSupport);
|
||||
FileSystem.SupportDir = SupportDir;
|
||||
|
||||
Utilities = new Utilities(args.GetValue("UtilityPath", "OpenRA.Utility.exe"));
|
||||
|
||||
Settings = new Settings(SupportDir + "settings.yaml", args);
|
||||
Settings = new Settings(Platform.SupportDir + "settings.yaml", args);
|
||||
Settings.Save();
|
||||
|
||||
Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar;
|
||||
Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
|
||||
Log.AddChannel("perf", "perf.log");
|
||||
Log.AddChannel("debug", "debug.log");
|
||||
Log.AddChannel("sync", "syncreport.log");
|
||||
@@ -340,25 +334,6 @@ namespace OpenRA
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
}
|
||||
|
||||
static string baseSupportDir = null;
|
||||
public static string SupportDir
|
||||
{
|
||||
set
|
||||
{
|
||||
var dir = value;
|
||||
|
||||
// Expand paths relative to the personal directory
|
||||
if (dir.ElementAt(0) == '~')
|
||||
dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir.Substring(1);
|
||||
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
baseSupportDir = dir + Path.DirectorySeparatorChar;
|
||||
}
|
||||
get { return baseSupportDir; }
|
||||
}
|
||||
|
||||
public static T CreateObject<T>( string name )
|
||||
{
|
||||
return modData.ObjectCreator.CreateObject<T>( name );
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace OpenRA
|
||||
Dictionary<string, Map> FindMaps(string[] mods)
|
||||
{
|
||||
var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p)))
|
||||
.Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Game.SupportDir, p))));
|
||||
.Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p))));
|
||||
|
||||
Dictionary<string, Map> ret = new Dictionary<string, Map>();
|
||||
foreach (var path in paths)
|
||||
|
||||
@@ -199,7 +199,6 @@
|
||||
<Compile Include="Network\Session.cs" />
|
||||
<Compile Include="ObjectCreator.cs" />
|
||||
<Compile Include="Network\SyncReport.cs" />
|
||||
<Compile Include="Platform.cs" />
|
||||
<Compile Include="Traits\EditorAppearance.cs" />
|
||||
<Compile Include="Traits\SubcellInit.cs" />
|
||||
<Compile Include="Traits\Target.cs" />
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
enum PlatformType
|
||||
{
|
||||
Unknown,
|
||||
Windows,
|
||||
OSX,
|
||||
Linux
|
||||
}
|
||||
|
||||
static class Platform
|
||||
{
|
||||
public static PlatformType CurrentPlatform
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentPlatform.Value;
|
||||
}
|
||||
}
|
||||
|
||||
static Lazy<PlatformType> currentPlatform = new Lazy<PlatformType>(GetCurrentPlatform);
|
||||
|
||||
static PlatformType GetCurrentPlatform()
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) return PlatformType.Windows;
|
||||
|
||||
try
|
||||
{
|
||||
var psi = new ProcessStartInfo("uname", "-s");
|
||||
psi.UseShellExecute = false;
|
||||
psi.RedirectStandardOutput = true;
|
||||
var p = Process.Start(psi);
|
||||
var kernelName = p.StandardOutput.ReadToEnd();
|
||||
if (kernelName.Contains("Linux") || kernelName.Contains("BSD"))
|
||||
return PlatformType.Linux;
|
||||
if (kernelName.Contains("Darwin"))
|
||||
return PlatformType.OSX;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return PlatformType.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = Utility;
|
||||
p.StartInfo.Arguments = "{0} --SupportDir \"{1}\"".F(args, Game.SupportDir);
|
||||
p.StartInfo.Arguments = args;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.EnableRaisingEvents = true;
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
void InstallMapInner(string path)
|
||||
{
|
||||
var toPath = "{0}{1}maps{1}{2}{1}{3}"
|
||||
.F(Game.SupportDir,Path.DirectorySeparatorChar,
|
||||
.F(Platform.SupportDir,Path.DirectorySeparatorChar,
|
||||
Game.modData.Manifest.Mods[0],
|
||||
Path.GetFileName(path));
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
/* find some replays? */
|
||||
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
|
||||
var replayDir = Path.Combine(Game.SupportDir, "Replays");
|
||||
var replayDir = Path.Combine(Platform.SupportDir, "Replays");
|
||||
|
||||
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
|
||||
CurrentReplay = null;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
public string PackagePath = "";
|
||||
public string InstallMode = "";
|
||||
|
||||
public string ResolvedPackagePath { get { return PackagePath.Replace("^", Game.SupportDir); } }
|
||||
public string ResolvedPackagePath { get { return PackagePath.Replace("^", Platform.SupportDir); } }
|
||||
|
||||
public override void DrawInner() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user