installation info: Refactor OS detection, support Ubuntu and GNOME
This commit is contained in:
parent
06766a57f6
commit
b9efe59200
|
@ -197,7 +197,7 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
string app_data_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
|
string app_data_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
|
||||||
|
|
||||||
if (InstallationInfo.Platform == PlatformID.Unix)
|
if (InstallationInfo.OperatingSystem != OS.Windows && InstallationInfo.OperatingSystem != OS.Mac)
|
||||||
app_data_path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".config");
|
app_data_path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".config");
|
||||||
|
|
||||||
string config_path = Path.Combine (app_data_path, "org.sparkleshare.SparkleShare");
|
string config_path = Path.Combine (app_data_path, "org.sparkleshare.SparkleShare");
|
||||||
|
@ -216,8 +216,9 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
Logger.LogInfo ("Environment", "SparkleShare " + InstallationInfo.Version);
|
Logger.LogInfo ("Environment", "SparkleShare " + InstallationInfo.Version);
|
||||||
Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion);
|
Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion);
|
||||||
Logger.LogInfo ("Environment", InstallationInfo.Platform + " (" + Environment.OSVersion + ")");
|
Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " (" + Environment.OSVersion + ")");
|
||||||
|
// todo tostring with nice os version names
|
||||||
|
|
||||||
Preset.PresetsPath = PresetsPath;
|
Preset.PresetsPath = PresetsPath;
|
||||||
InstallProtocolHandler ();
|
InstallProtocolHandler ();
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ namespace SparkleShare {
|
||||||
Arguments = args;
|
Arguments = args;
|
||||||
|
|
||||||
if (args.Length != 0 && (args [0].Equals ("help") || args [0].Equals ("version")) &&
|
if (args.Length != 0 && (args [0].Equals ("help") || args [0].Equals ("version")) &&
|
||||||
InstallationInfo.Platform != PlatformID.MacOSX &&
|
InstallationInfo.OperatingSystem != OS.Mac &&
|
||||||
InstallationInfo.Platform != PlatformID.Win32NT) {
|
InstallationInfo.OperatingSystem != OS.Windows) {
|
||||||
|
|
||||||
string n = Environment.NewLine;
|
string n = Environment.NewLine;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace Sparkles {
|
||||||
|
|
||||||
public string HomePath {
|
public string HomePath {
|
||||||
get {
|
get {
|
||||||
if (InstallationInfo.Platform == PlatformID.Win32NT)
|
if (InstallationInfo.OperatingSystem == OS.Windows)
|
||||||
return Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
|
return Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
|
||||||
|
|
||||||
return Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
return Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
||||||
|
@ -113,12 +113,11 @@ namespace Sparkles {
|
||||||
{
|
{
|
||||||
string user_name = Environment.UserName;
|
string user_name = Environment.UserName;
|
||||||
|
|
||||||
if (InstallationInfo.Platform == PlatformID.Unix ||
|
if (InstallationInfo.OperatingSystem != OS.Windows) {
|
||||||
InstallationInfo.Platform == PlatformID.MacOSX) {
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty (user_name))
|
if (string.IsNullOrEmpty (user_name))
|
||||||
user_name = "Unknown";
|
user_name = "Unknown";
|
||||||
else
|
else
|
||||||
|
// On Unix systems the user name may have commas appended
|
||||||
user_name = user_name.TrimEnd (',');
|
user_name = user_name.TrimEnd (',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace Sparkles.Git {
|
||||||
"push.default matching"
|
"push.default matching"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (InstallationInfo.Platform == PlatformID.Win32NT)
|
if (InstallationInfo.OperatingSystem == OS.Windows)
|
||||||
settings [0] = "core.autocrlf true";
|
settings [0] = "core.autocrlf true";
|
||||||
|
|
||||||
foreach (string setting in settings) {
|
foreach (string setting in settings) {
|
||||||
|
|
|
@ -17,44 +17,52 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace Sparkles {
|
namespace Sparkles {
|
||||||
|
|
||||||
|
public enum OS
|
||||||
|
{
|
||||||
|
Mac,
|
||||||
|
Windows,
|
||||||
|
Ubuntu,
|
||||||
|
GNOME
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public partial class InstallationInfo {
|
public partial class InstallationInfo {
|
||||||
|
|
||||||
|
static OS operating_system = OS.Windows;
|
||||||
|
|
||||||
|
public static OS OperatingSystem {
|
||||||
|
get {
|
||||||
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
|
return operating_system;
|
||||||
|
|
||||||
|
var uname = new Command ("uname", "-a");
|
||||||
|
string output = uname.StartAndReadStandardOutput ();
|
||||||
|
|
||||||
|
// Environment.OSVersion.Platform.PlatformID.MacOSX is broken in Mono
|
||||||
|
// for historical reasons, so check manually
|
||||||
|
if (output.StartsWith ("Darwin", StringComparison.InvariantCulture)) {
|
||||||
|
operating_system = OS.Mac;
|
||||||
|
|
||||||
|
} else if (output.Contains ("Ubuntu")) {
|
||||||
|
operating_system = OS.Ubuntu;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
operating_system = OS.GNOME;
|
||||||
|
}
|
||||||
|
|
||||||
|
return operating_system;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static string Version {
|
public static string Version {
|
||||||
get {
|
get {
|
||||||
string version = "" + Assembly.GetExecutingAssembly ().GetName ().Version;
|
string version = "" + Assembly.GetExecutingAssembly ().GetName ().Version;
|
||||||
return version.Substring (0, version.Length - 2);
|
return version.Substring (0, version.Length - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
|
|
||||||
// which is intentionally broken in Mono for historical reasons
|
|
||||||
public static PlatformID Platform {
|
|
||||||
get {
|
|
||||||
IntPtr buf = IntPtr.Zero;
|
|
||||||
|
|
||||||
try {
|
|
||||||
buf = Marshal.AllocHGlobal (8192);
|
|
||||||
|
|
||||||
if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin")
|
|
||||||
return PlatformID.MacOSX;
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
} finally {
|
|
||||||
if (buf != IntPtr.Zero)
|
|
||||||
Marshal.FreeHGlobal (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Environment.OSVersion.Platform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[DllImport ("libc")]
|
|
||||||
static extern int uname (IntPtr buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace Sparkles {
|
||||||
{
|
{
|
||||||
string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
||||||
|
|
||||||
if (InstallationInfo.Platform == PlatformID.Win32NT)
|
if (InstallationInfo.OperatingSystem == OS.Windows)
|
||||||
home_path = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
|
home_path = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
|
||||||
|
|
||||||
string crash_report_file_path = Path.Combine (home_path, "SparkleShare", "crash_report.txt");
|
string crash_report_file_path = Path.Combine (home_path, "SparkleShare", "crash_report.txt");
|
||||||
|
|
Loading…
Reference in a new issue