Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Fluctio.FluctioSim.Common.Configuration;

namespace Fluctio.FluctioSim.EditorUtils.OperatingSystem
{
	public static class Platform
	{
		public static PlatformType Type { get; } = GetPlatformType();
		
		public static readonly string DocumentsFolderPath =
			Path.Combine(
				Environment.GetFolderPath(
					Environment.SpecialFolder.MyDocuments,
					Environment.SpecialFolderOption.DoNotVerify
				),
				Config.PackageId
			);

		public static IEnumerable<string> EnvironmentPath
		{
			get
			{
				var pathString = Environment.GetEnvironmentVariable("PATH") ?? "";
				if (Type is PlatformType.MacOS or PlatformType.Linux)
				{
					// .NET on OSX/Linux does not retrieve user-wide variables
					// TODO: there should be a better way than hardcode. Maybe running shell command with UseShellExecute = true?
					pathString = $"/usr/local/bin:{pathString}";
				}
				var pathArray = pathString.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
				return pathArray.Select(Environment.ExpandEnvironmentVariables);
			}
		}

		public static NotSupportedException OSNotSupportedException => new($"Operating system is not supported ({Environment.OSVersion.VersionString})");

		// getting the real Downloads folder consistently on different operating systems is a nightmare
		public static readonly string DownloadsFolderPath = DocumentsFolderPath;
		
		private static PlatformType GetPlatformType()
		{
			if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
			{
				return PlatformType.MacOS;
			}
			if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
			{
				return PlatformType.Linux;
			}
			if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
			{
				return PlatformType.Windows;
			}
			return PlatformType.Other;
		}
	}
	
	public enum PlatformType
	{
		Windows,
		Linux,
		MacOS,
		Other,
	}
}