Пример #1
0
        /// <summary>
        /// Return codes:
        /// 0 - The operation completed successfully.
        /// 59 - An unexpected network error occurred.
        /// 1223 - The operation was canceled by the user.
        ///
        /// Commands
        /// u[ninstall] [/s[ilent]] AppID     - Uninstall an app
        /// i[nfo] AppID                      - Show info about an app
        /// l[ist]                            - List app ID's
        /// steam                             - Show Steam install location
        /// </summary>
        private static int Main(string[] args)
        {
            try
            {
                try { Console.OutputEncoding = Encoding.Unicode; }
                catch (IOException) { /*Old .NET v4 without support for unicode output*/ }

                ProcessCommandlineArguments(args);

                switch (_queryType)
                {
                case QueryType.GetInfo:
                    var appInfo = SteamApplicationInfo.FromAppId(_appId);
                    foreach (var property in typeof(SteamApplicationInfo).GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        Console.WriteLine("{0} - {1}", property.Name, property.GetValue(appInfo, null) ?? "N/A");
                    }
                    break;

                case QueryType.Uninstall:
                    SteamUninstaller.UninstallSteamApp(SteamApplicationInfo.FromAppId(_appId), _silent);
                    break;

                case QueryType.List:
                    foreach (var result in SteamInstallation.Instance.SteamAppsLocations
                             .SelectMany(x => Directory.GetFiles(x, @"appmanifest_*.acf")
                                         .Select(p => Path.GetFileNameWithoutExtension(p).Substring(12)))
                             .Select(x => int.TryParse(x, out var num) ? num : (int?)null)
                             .Where(x => x != null)
                             .OrderBy(x => x))
                    {
                        Console.WriteLine(result);
                    }
                    break;

                case QueryType.SteamDir:
                    Console.WriteLine(SteamInstallation.Instance.InstallationDirectory);
                    break;
                }
            }
            catch (OperationCanceledException)
            {
                return((int)ReturnValue.CancelledByUserCode);
            }
            catch (FormatException ex)
            {
                LogWriter.WriteExceptionToLog(ex);
                return((int)ReturnValue.InvalidArgumentCode);
            }
            catch (Exception ex)
            {
                LogWriter.WriteExceptionToLog(ex);
                return((int)ReturnValue.UnexpectedNetworkErrorCode);
            }
            return((int)ReturnValue.OkCode);
        }
Пример #2
0
        /// <summary>
        /// Return codes:
        /// 0 - The operation completed successfully.
        /// 59 - An unexpected network error occurred.
        /// 1223 - The operation was canceled by the user.
        ///
        /// Commands
        /// u[ninstall] [/s[ilent]] AppID     - Uninstall an app
        /// i[nfo] AppID                      - Show info about an app
        /// l[ist]                            - List app ID's
        /// steam                             - Show Steam install location
        /// </summary>
        private static int Main(string[] args)
        {
            try
            {
                Console.OutputEncoding = Encoding.Unicode;

                ProcessCommandlineArguments(args);

                switch (_queryType)
                {
                case QueryType.GetInfo:
                    var appInfo = SteamApplicationInfo.FromAppId(_appId);
                    foreach (var property in typeof(SteamApplicationInfo).GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        Console.WriteLine("{0} - {1}", property.Name, property.GetValue(appInfo, null) ?? "N/A");
                    }
                    break;

                case QueryType.Uninstall:
                    SteamUninstaller.UninstallSteamApp(SteamApplicationInfo.FromAppId(_appId), _silent);
                    break;

                case QueryType.List:
                    foreach (var result in SteamInstallation.Instance.SteamAppsLocations
                             .SelectMany(x => Directory.GetFiles(x, @"appmanifest_*.acf")
                                         .Select(p => (Path.GetFileNameWithoutExtension(p)?.Substring(12))).Where(p => p != null))
                             .Select(int.Parse).OrderBy(x => x))
                    {
                        Console.WriteLine(result);
                    }
                    break;

                case QueryType.SteamDir:
                    Console.WriteLine(SteamInstallation.Instance.InstallationDirectory);
                    break;
                }
            }
            catch (OperationCanceledException)
            {
                return(1223);
            }
            catch (FormatException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
                return(InvalidArgumentCode);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
                return(59);
            }
            return(0);
        }