Пример #1
0
        public QueryUGCChildren WaitForResult()
        {
            if (DependencyCount == 0)
            {
                return(this);
            }

            // Wait for Response
            while (!Finished && !Cancelled)
            {
                Thread.Sleep(10);
                SteamAPIWrapper.RunCallbacks();
            }

            if (Cancelled)
            {
                return(this);
            }

            var idList = new PublishedFileId_t[DependencyCount];

            Success = SteamUGC.GetQueryUGCChildren(_queryHandle, 0, idList, (uint)idList.Length);
            SteamUGC.ReleaseQueryUGCRequest(_queryHandle);
            Result = idList.ToList().ConvertAll(item => item.m_PublishedFileId);

            return(this);
        }
Пример #2
0
        public ItemDetailsRequest WaitForResult()
        {
            // Wait for Response
            while (!Finished && !Cancelled)
            {
                Thread.Sleep(10);
                SteamAPIWrapper.RunCallbacks();
            }

            if (Cancelled)
            {
                return(this);
            }

            Result = new List <SteamUGCDetails_t>();

            for (uint i = 0; i < Identifiers.Count; i++)
            {
                // Retrieve Value
                Success = SteamUGC.GetQueryUGCResult(_queryHandle, i, out var result);
                Result.Add(result);
            }

            SteamUGC.ReleaseQueryUGCRequest(_queryHandle);
            return(this);
        }
Пример #3
0
        /// <summary>
        /// Runs War of the Chosen with the selected arguments
        /// </summary>
        /// <param name="gameDir"></param>
        /// <param name="args"></param>
        public static void RunWotC(string gameDir, string args)
        {
            Log.Info("Starting WotC");

            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Could not connect to steam.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var p = new Process
            {
                StartInfo =
                {
                    Arguments        = args,
                    FileName         = gameDir + @"\XCom2-WarOfTheChosen\Binaries\Win64\XCom2.exe",
                    WorkingDirectory = gameDir + @"\XCom2-WarOfTheChosen"
                }
            };

            try
            {
                p.Start();
            }
            catch (Win32Exception ex)
            {
                Log.Warn("Failed to start game process", ex);
                MessageBox.Show("An error occured while trying to run the game. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            SteamAPIWrapper.Shutdown();
        }
Пример #4
0
        public static void Unsubscribe(ulong id)
        {
            SteamAPIWrapper.Init();

            SteamUGC.UnsubscribeItem(id.ToPublishedFileID());
            SteamAPIWrapper.RunCallbacks();
        }
Пример #5
0
        public override void RunGame(string gameDir, string args)
        {
            Log.Info("Starting XCOM Chimera Squad");

            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Could not connect to steam.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var p = new Process
            {
                StartInfo =
                {
                    Arguments        = args,
                    FileName         = gameDir + @"\Binaries\Win64\xcom.exe",
                    WorkingDirectory = gameDir
                }
            };

            try
            {
                p.Start();
            }
            catch (Win32Exception ex)
            {
                Log.Warn("Failed to start game process", ex);
                MessageBox.Show("An error occured while trying to run the game. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            SteamAPIWrapper.Shutdown();
        }
Пример #6
0
        public MainForm(Settings settings)
        {
            InitializeComponent();

            appRestartPendingLabel.Visible = false;

            // Settings
            SteamAPIWrapper.Init();
            Settings = settings;

            // Restore states
            showHiddenModsToolStripMenuItem.Checked = settings.ShowHiddenElements;

            // Hide WotC and Challenge Mode buttons if necessary
            if (settings.GamePath != "")
            {
                var wotcAvailable = Directory.Exists(settings.GamePath + @"\XCom2-WarOfTheChosen");
                runWarOfTheChosenToolStripMenuItem.Visible = wotcAvailable;
                runChallengeModeToolStripMenuItem.Visible  = wotcAvailable;
                importFromWotCToolStripMenuItem.Visible    = wotcAvailable;
            }

            // Init interface
            InitObjectListView();
            UpdateInterface();
            RegisterEvents();

            //Other intialization
            InitializeTabImages();

            // Init the argument checkboxes
            UpdateQuickArgumentsMenu();

#if !DEBUG
            // Check for Updates
            CheckSteamForUpdates();
#endif

            // Run callbacks
            var t1 = new Timer();
            t1.Tick    += (sender, e) => { SteamAPIWrapper.RunCallbacks(); };
            t1.Interval = 10;
            t1.Start();

            // Check for running downloads
#if DEBUG
            if (Settings.GetWorkshopPath() != null)
            {
                CheckSteamForNewMods();

                var t2 = new Timer();
                t2.Tick    += (sender, e) => { CheckSteamForNewMods(); };
                t2.Interval = 30000;
                t2.Start();
            }
#endif
        }
Пример #7
0
        private void Update()
        {
            if (!m_bInitialized)
            {
                return;
            }

            // Run Steam client callbacks
            SteamAPIWrapper.RunCallbacks();
        }
Пример #8
0
        public const int MAX_UGC_RESULTS = 50; // according to 

        public static ulong[] GetSubscribedItems()
        {
            SteamAPIWrapper.Init();

            var num = SteamUGC.GetNumSubscribedItems();
            var ids = new PublishedFileId_t[num];
            SteamUGC.GetSubscribedItems(ids, num);

            return ids.Select(t => t.m_PublishedFileId).ToArray();
        }
Пример #9
0
        public MainForm(Settings settings)
        {
            //
            InitializeComponent();

            // Settings
            SteamAPIWrapper.InitSafe();
            Settings = settings;

            // Restore states
            showHiddenModsToolStripMenuItem.Checked = settings.ShowHiddenElements;

            // Hide WotC button if necessary
            runWarOfTheChosenToolStripMenuItem.Visible = Directory.Exists(settings.GamePath + @"\XCom2-WarOfTheChosen");

            // Init interface
            InitObjectListView();
            UpdateInterface();
            RegisterEvents();

            //Other intialization
            InitializeTabImages();

            // Init the argument checkboxes
            LogLaunchArgument.Settings          = settings;
            NoRedscreensLaunchArgument.Settings = settings;

#if !DEBUG
            // Check for Updates
            CheckSteamForUpdates();
#endif

            // Run callbacks
            var t1 = new Timer();
            t1.Tick    += (sender, e) => { SteamAPIWrapper.RunCallbacks(); };
            t1.Interval = 10;
            t1.Start();

            // Check for running downloads
#if DEBUG
            if (Settings.GetWorkshopPath() != null)
            {
                CheckSteamForNewMods();

                var t2 = new Timer();
                t2.Tick    += (sender, e) => { CheckSteamForNewMods(); };
                t2.Interval = 30000;
                t2.Start();
            }
#endif
        }
Пример #10
0
        public ItemDetailsRequest Send()
        {
            SteamAPIWrapper.Init();

            _onQueryCompleted = CallResult <SteamUGCQueryCompleted_t> .Create(QueryCompleted);

            _queryHandle = SteamUGC.CreateQueryUGCDetailsRequest(new[] { ID.ToPublishedFileID() }, 1);

            var apiCall = SteamUGC.SendQueryUGCRequest(_queryHandle);

            _onQueryCompleted.Set(apiCall);

            return(this);
        }
Пример #11
0
        // OnApplicationQuit gets called too early to shutdown the SteamAPIWrapper.
        // Because the SteamManager should be persistent and never disabled or destroyed we can shutdown the SteamAPI here.
        // Thus it is not recommended to perform any Steamworks work in other OnDestroy functions as the order of execution can not be garenteed upon Shutdown. Prefer OnDisable().
        private void OnDestroy()
        {
            if (s_instance != this)
            {
                return;
            }

            s_instance = null;

            if (!m_bInitialized)
            {
                return;
            }

            SteamAPIWrapper.Shutdown();
        }
Пример #12
0
        public static UpdateInfo GetDownloadInfo(ulong id)
        {
            SteamAPIWrapper.Init();

            ulong punBytesProcessed;
            ulong punBytesTotal;

            SteamUGC.GetItemDownloadInfo(new PublishedFileId_t(id), out punBytesProcessed, out punBytesTotal);

            return(new UpdateInfo
            {
                ItemID = id,
                BytesProcessed = punBytesProcessed,
                BytesTotal = punBytesTotal
            });
        }
Пример #13
0
        public static InstallInfo GetInstallInfo(ulong id)
        {
            SteamAPIWrapper.Init();

            ulong  punSizeOnDisk;
            string pchFolder;
            uint   punTimeStamp;

            SteamUGC.GetItemInstallInfo(new PublishedFileId_t(id), out punSizeOnDisk, out pchFolder, 256, out punTimeStamp);

            return(new InstallInfo
            {
                ItemID = id,
                SizeOnDisk = punSizeOnDisk,
                Folder = pchFolder,
                TimeStamp = new DateTime(punTimeStamp * 10)
            });
        }
Пример #14
0
        public MainForm(Settings settings)
        {
            //
            InitializeComponent();

            // Settings
            SteamAPIWrapper.InitSafe();
            Settings = settings;

            // Restore states
            showHiddenModsToolStripMenuItem.Checked = settings.ShowHiddenElements;

            // Init interface
            InitObjectListView();
            UpdateInterface();
            RegisterEvents();

            //Other intialization
            InitializeTabImages();

#if !DEBUG
            // Check for Updates
            CheckSteamForUpdates();
#endif

            // Run callbacks
            var t1 = new Timer();
            t1.Tick    += (sender, e) => { SteamAPIWrapper.RunCallbacks(); };
            t1.Interval = 10;
            t1.Start();

            // Check for running downloads
#if DEBUG
            if (Settings.GetWorkshopPath() != null)
            {
                CheckSteamForNewMods();

                var t2 = new Timer();
                t2.Tick    += (sender, e) => { CheckSteamForNewMods(); };
                t2.Interval = 30000;
                t2.Start();
            }
#endif
        }
Пример #15
0
        public ItemDetailsRequest Send()
        {
            SteamAPIWrapper.Init();

            PublishedFileId_t[] idList = Identifiers.ConvertAll(id => new PublishedFileId_t(id)).ToArray();

            _onQueryCompleted = CallResult <SteamUGCQueryCompleted_t> .Create(QueryCompleted);

            _queryHandle = SteamUGC.CreateQueryUGCDetailsRequest(idList, (uint)idList.Length);

            SteamUGC.SetReturnLongDescription(_queryHandle, GetFullDescription);
            SteamUGC.SetReturnChildren(_queryHandle, true);     // required, otherwise m_unNumChildren will always be 0

            var apiCall = SteamUGC.SendQueryUGCRequest(_queryHandle);

            _onQueryCompleted.Set(apiCall);

            return(this);
        }
Пример #16
0
        public MainForm(Settings settings)
        {
            //
            InitializeComponent();

            // Settings
            SteamAPIWrapper.InitSafe();
            Settings = settings;

            // Restore states
            showHiddenModsToolStripMenuItem.Checked = settings.ShowHiddenElements;

#if !DEBUG
            // hide config tab
            modinfo_config_tab.Parent.Controls.Remove(modinfo_config_tab);
#endif

            // Init interface
            InitObjectListView();
            UpdateInterface();
            RegisterEvents();

            //Other intialization
            InitializeTabImages();

            // Check for Updates
            CheckSteamForUpdates();

            // Check for running downloads
#if DEBUG
            if (Settings.GetWorkshopPath() != null)
            {
                CheckSteamForNewMods();

                var t = new Timer();
                t.Tick    += (sender, e) => { CheckSteamForNewMods(); };
                t.Interval = 30000;
                t.Start();
            }
#endif
        }
Пример #17
0
        public QueryUGCChildren Send()
        {
            if (DependencyCount == 0)
            {
                return(this);
            }

            SteamAPIWrapper.Init();

            _onQueryCompleted = CallResult <SteamUGCQueryCompleted_t> .Create(QueryCompleted);

            _queryHandle = SteamUGC.CreateQueryUGCDetailsRequest(new[] { Id.ToPublishedFileID() }, 1);

            //SteamUGC.SetReturnLongDescription(_queryHandle, GetFullDescription);
            SteamUGC.SetReturnChildren(_queryHandle, true);

            var apiCall = SteamUGC.SendQueryUGCRequest(_queryHandle);

            _onQueryCompleted.Set(apiCall);

            return(this);
        }
        public ItemDetailsRequest WaitForResult()
        {
            // Wait for Response
            while (!Finished && !Cancelled)
            {
                Thread.Sleep(10);
                SteamAPIWrapper.RunCallbacks();
            }

            if (Cancelled)
            {
                return(this);
            }

            // Retrieve Value
            SteamUGCDetails_t result;

            Success = SteamUGC.GetQueryUGCResult(_queryHandle, 0, out result);

            Result = result;
            return(this);
        }
Пример #19
0
        /// <summary>
        /// Runs War of the Chosen with the selected arguments
        /// </summary>
        /// <param name="gameDir"></param>
        /// <param name="args"></param>
        public static void RunWotC(string gameDir, string args)
        {
            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Could not connect to steam.");
            }


            var p = new Process
            {
                StartInfo =
                {
                    Arguments        = args,
                    FileName         = gameDir + @"\XCom2-WarOfTheChosen\Binaries\Win64\XCom2.exe",
                    WorkingDirectory = gameDir + @"\XCom2-WarOfTheChosen"
                }
            };

            p.Start();

            SteamAPIWrapper.Shutdown();
        }
Пример #20
0
        /// <summary>
        /// Runs the game with the selected arguments
        /// </summary>
        /// <param name="gameDir"></param>
        /// <param name="args"></param>
        public static void RunGame(string gameDir, string args)
        {
            Log.Info("Starting XCOM 2 (vanilla)");

            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Could not connect to steam.");
            }

            var p = new Process
            {
                StartInfo =
                {
                    Arguments        = args,
                    FileName         = gameDir + @"\Binaries\Win64\XCom2.exe",
                    WorkingDirectory = gameDir
                }
            };

            p.Start();

            SteamAPIWrapper.Shutdown();
        }
Пример #21
0
        public static void Subscribe(ulong id)
        {
            SteamAPIWrapper.Init();

            SteamUGC.SubscribeItem(id.ToPublishedFileID());
        }
Пример #22
0
        public MainForm(Settings settings)
        {
            InitializeComponent();

            appRestartPendingLabel.Visible           = false;
            aboutToolStripMenuItem.DropDownDirection = ToolStripDropDownDirection.BelowLeft;

            // Settings
            SteamAPIWrapper.Init();
            Settings = settings;

            // Restore states
            showHiddenModsToolStripMenuItem.Checked = settings.ShowHiddenElements;
            cShowStateFilter.Checked       = settings.ShowStateFilter;
            cEnableGrouping.Checked        = settings.ShowModListGroups;
            cShowPrimaryDuplicates.Checked = Settings.ShowPrimaryDuplicateAsDependency;
            cShowPrimaryDuplicates.Visible = Settings.EnableDuplicateModIdWorkaround;
            modlist_ListObjectListView.UseTranslucentSelection = Settings.UseTranslucentModListSelection;
            olvRequiredMods.UseTranslucentSelection            = Settings.UseTranslucentModListSelection;
            olvDependentMods.UseTranslucentSelection           = Settings.UseTranslucentModListSelection;

            // Set visibility of some controls depending on game type
            var wotcAvailable = Directory.Exists(settings.GamePath + @"\XCom2-WarOfTheChosen");

            runXCOM2ToolStripMenuItem.Visible               = Program.XEnv.Game == GameId.X2;
            runWarOfTheChosenToolStripMenuItem.Visible      = wotcAvailable && Program.XEnv.Game == GameId.X2;
            runChallengeModeToolStripMenuItem.Visible       = wotcAvailable && Program.XEnv.Game == GameId.X2;
            importFromWotCToolStripMenuItem.Visible         = wotcAvailable && Program.XEnv.Game == GameId.X2;
            importFromXCOM2ToolStripMenuItem.Visible        = Program.XEnv.Game == GameId.X2;
            runChimeraSquadToolStripMenuItem.Visible        = Program.XEnv.Game == GameId.ChimeraSquad;
            importFromChimeraSquadToolStripMenuItem.Visible = Program.XEnv.Game == GameId.ChimeraSquad;

            if (Program.XEnv.Game != GameId.X2)
            {
                modlist_ListObjectListView.AllColumns.Remove(olvForWOTC);
                modlist_ListObjectListView.RebuildColumns();
                olvDependentMods.AllColumns.Remove(olvColDepModsWotc);
                olvDependentMods.RebuildColumns();
                olvRequiredMods.AllColumns.Remove(olvColReqModsWotc);
                olvRequiredMods.RebuildColumns();
            }

            // If game path is not configured, hide several function/options.
            if (string.IsNullOrEmpty(settings.GamePath))
            {
                runWarOfTheChosenToolStripMenuItem.Enabled      = false;
                runChallengeModeToolStripMenuItem.Enabled       = false;
                importFromWotCToolStripMenuItem.Enabled         = false;
                importFromXCOM2ToolStripMenuItem.Enabled        = false;
                importFromChimeraSquadToolStripMenuItem.Enabled = false;
            }

            // Init interface
            InitModListView();
            InitDependencyListViews();
            UpdateInterface();
            RegisterEvents();

            // Other intialization
            InitializeTabImages();

            // Init the argument checkboxes
            InitQuickArgumentsMenu(settings);

#if !DEBUG
            // Update mod information
            var mods = Settings.Mods.All.ToList();

            UpdateMods(mods, () =>
            {
                modlist_ListObjectListView.RefreshObjects(mods);
            });
#endif
            // Run callbacks
            var t1 = new Timer();
            t1.Tick    += (sender, e) => { SteamAPIWrapper.RunCallbacks(); };
            t1.Interval = 10;
            t1.Start();

/*
 *          // Check for running downloads
 #if DEBUG
 *          if (Settings.GetWorkshopPath() != null)
 *          {
 *              CheckSteamForNewMods();
 *
 *              var t2 = new Timer();
 *              t2.Tick += (sender, e) => { CheckSteamForNewMods(); };
 *              t2.Interval = 30000;
 *              t2.Start();
 *          }
 #endif
 */
        }
Пример #23
0
 public void Send()
 {
     SteamAPIWrapper.Init();
     SteamUGC.DownloadItem(new PublishedFileId_t(_id), true);
 }
Пример #24
0
 public static EItemState GetDownloadStatus(ulong id)
 {
     SteamAPIWrapper.Init();
     return((EItemState)SteamUGC.GetItemState(new PublishedFileId_t(id)));
 }
Пример #25
0
        public MainForm(Settings settings)
        {
            InitializeComponent();

            appRestartPendingLabel.Visible           = false;
            progress_toolstrip_progressbar.Visible   = false;
            aboutToolStripMenuItem.DropDownDirection = ToolStripDropDownDirection.BelowLeft;

            // Settings
            SteamAPIWrapper.Init();
            Settings = settings;

            // Restore states
            InitMainGui(settings);

            // Init interface
            InitModListView();
            InitDependencyListViews();
            UpdateInterface();
            RegisterEvents();

            // Other intialization
            InitializeTabImages();

            // Init the argument checkboxes
            InitQuickArgumentsMenu(settings);

            #if !DEBUG
            // Update mod information
            var mods = Settings.Mods.All.ToList();

            if (settings.OnlyUpdateEnabledOrNewModsOnStartup)
            {
                mods = mods.Where(mod => mod.isActive || mod.State.HasFlag(ModState.New)).ToList();
            }

            UpdateMods(mods, () =>
            {
                modlist_ListObjectListView.RefreshObjects(mods);
            });
            #endif

            // Run callbacks
            var t1 = new Timer();
            t1.Tick    += (sender, e) => { SteamAPIWrapper.RunCallbacks(); };
            t1.Interval = 10;
            t1.Start();

/*
 *          // Check for running downloads
 #if DEBUG
 *          if (Settings.GetWorkshopPath() != null)
 *          {
 *              CheckSteamForNewMods();
 *
 *              var t2 = new Timer();
 *              t2.Tick += (sender, e) => { CheckSteamForNewMods(); };
 *              t2.Interval = 30000;
 *              t2.Start();
 *          }
 #endif
 */
        }
Пример #26
0
        private void Awake()
        {
            // Only one instance of SteamManager at a time!
            if (s_instance != null)
            {
                //Destroy(gameObject);
                return;
            }
            s_instance = this;

            if (s_EverInialized)
            {
                // This is almost always an error.
                // The most common case where this happens is the SteamManager getting desstroyed via Application.Quit() and having some code in some OnDestroy which gets called afterwards, creating a new SteamManager.
                throw new System.Exception("Tried to Initialize the SteamAPI twice in one session!");
            }

            // We want our SteamManager Instance to persist across scenes.
            //DontDestroyOnLoad(gameObject);

            if (!Packsize.Test())
            {
                Debug.Fail("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.");
            }

            if (!DllCheck.Test())
            {
                Debug.Fail("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.");
            }

            try
            {
                // If Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
                // Steam client and also launches this game again if the User owns it. This can act as a rudimentary form of DRM.

                // Once you get a Steam AppID assigned by Valve, you need to replace AppId_t.Invalid with it and
                // remove steam_appid.txt from the game depot. eg: "(AppId_t)480" or "new AppId_t(480)".
                // See the Valve documentation for more information: https://partner.steamgames.com/documentation/drm#FAQ
                if (SteamAPIWrapper.RestartAppIfNecessary(AppId_t.Invalid))
                {
                    System.Windows.Forms.Application.Exit();
                    return;
                }
            }
            catch (System.DllNotFoundException e)
            { // We catch this exception here, as it will be the first occurence of it.
                Debug.Fail("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + e);

                System.Windows.Forms.Application.Exit();
                return;
            }

            // Initialize the SteamAPI, if Init() returns false this can happen for many reasons.
            // Some examples include:
            // Steam Client is not running.
            // Launching from outside of steam without a steam_appid.txt file in place.
            // Running under a different OS User or Access level (for example running "as administrator")
            // Valve's documentation for this is located here:
            // https://partner.steamgames.com/documentation/getting_started
            // https://partner.steamgames.com/documentation/example // Under: Common Build Problems
            // https://partner.steamgames.com/documentation/bootstrap_stats // At the very bottom

            // If you're running into Init issues try running DbgView prior to launching to get the internal output from Steam.
            // http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
            m_bInitialized = SteamAPIWrapper.Init();
            if (!m_bInitialized)
            {
                Debug.Fail("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.");

                return;
            }

            s_EverInialized = true;
        }
Пример #27
0
        private static void Main()
        {
            if (!IsDebugBuild)
            {
                // Capture all unhandled Exceptions
                AppDomain.CurrentDomain.UnhandledException += (sender, args) => HandleUnhandledException(args.ExceptionObject as Exception, "UnhandledException");
                Application.ThreadException += (sender, args) => HandleUnhandledException(args.Exception, "ThreadException");
            }

            // Mutex is used to check if another instance of AML is already running
            Mutex       mutex             = new Mutex(true, "E3241D27-3DD8-4615-888A-502252B9E2A1", out var isFirstInstance);
            IDisposable sentrySdkInstance = null;

            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                InitAppSettings();
                sentrySdkInstance = InitSentry();

                if (!CheckDotNet4_7_2())
                {
                    Log.Warn(".NET Framework v4.7.2 required");

                    var result = MessageBox.Show("This program requires Microsoft .NET Framework v4.7.2 or newer. Do you want to open the download page now?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    if (result == DialogResult.Yes)
                    {
                        Tools.StartProcess("https://dotnet.microsoft.com/download/dotnet-framework");
                    }

                    return;
                }

                if (!SteamAPIWrapper.Init())
                {
                    Log.Warn("Failed to detect Steam");

                    StringBuilder message = new StringBuilder();
                    message.AppendLine("Please make sure that:");
                    message.AppendLine("- Steam is running");
                    message.AppendLine("- the file steam_appid.txt exists in the AML folder");
                    message.AppendLine("- neither (or both) of Steam and AML are running\n  with admin privileges");
                    MessageBox.Show(message.ToString(), "Error - unable to detect Steam!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Load settings
                var settings = InitializeSettings();
                if (settings == null)
                {
                    Log.Error("Failed to initialize settings");
                    return;
                }

                // Exit if another instance of AML is already running and multiple instances are disabled.
                if (!settings.AllowMultipleInstances && !isFirstInstance)
                {
                    MessageBox.Show("Another instance of AML is already running.", "AML already started", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Check for update
                if (!IsDebugBuild && settings.CheckForUpdates)
                {
                    CheckForUpdate();
                }

                // clean up old files
                if (File.Exists(Program.XEnv.DefaultConfigDir + @"\DefaultModOptions.ini.bak"))
                {
                    // Restore backup
                    File.Copy(Program.XEnv.DefaultConfigDir + @"\DefaultModOptions.ini.bak", Program.XEnv.DefaultConfigDir + @"\DefaultModOptions.ini", true);
                    File.Delete(Program.XEnv.DefaultConfigDir + @"\DefaultModOptions.ini.bak");
                }

                Application.Run(new MainForm(settings));
                SteamAPIWrapper.Shutdown();
            }
            finally
            {
                Log.Info("Shutting down...");
                sentrySdkInstance?.Dispose();
                GlobalSettings.Instance.Save();
                GC.KeepAlive(mutex);    // prevent the mutex from being garbage collected early
                mutex.Dispose();
            }
        }
Пример #28
0
        private static void Main()
        {
#if !DEBUG
            try
            {
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!CheckDotNet4_6() && MessageBox.Show("This program requires .NET v4.6 or newer.\r\nDo you want to install it now?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Process.Start(@"https://www.microsoft.com/de-de/download/details.aspx?id=49981");
            }

            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Please start steam first!");
                return;
            }
            // SteamWorkshop.StartCallbackService();


            // Load settings
            var settings = InitializeSettings();
            if (settings == null)
            {
                return;
            }

#if !DEBUG
            // Check for update
            if (settings.CheckForUpdates)
            {
                try
                {
                    using (var client = new System.Net.WebClient())
                    {
                        client.Headers.Add("User-Agent: Other");
                        var json           = client.DownloadString("https://api.github.com/repos/aEnigmatic/xcom2-launcher/releases/latest");
                        var release        = Newtonsoft.Json.JsonConvert.DeserializeObject <GitHub.Release>(json);
                        var currentVersion = GetCurrentVersion();

                        if (currentVersion != release.tag_name)
                        {
                            // New version available
                            new UpdateAvailableDialog(release, currentVersion).ShowDialog();
                        }
                    }
                }
                catch (System.Net.WebException)
                {
                    // No internet?
                }
            }
#endif

            // clean up old files
            if (File.Exists(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak"))
            {
                // Restore backup
                File.Copy(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak", XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini", true);
                File.Delete(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak");
            }

            Application.Run(new MainForm(settings));

            SteamAPIWrapper.Shutdown();
#if !DEBUG
        }

        catch (Exception e)
        {
            MessageBox.Show("An exception occured. See error.log for additional details.");
            File.WriteAllText("error.log", e.Message + "\r\nStack:\r\n" + e.StackTrace);
        }
#endif
        }
Пример #29
0
        private static void Main()
        {
#if !DEBUG
            try
            {
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!CheckDotNet4_6())
            {
                var result = MessageBox.Show("This program requires Microsoft .NET Framework v4.6 or newer. Do you want to open the download page now?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                if (result == DialogResult.Yes)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=56115");
                }

                return;
            }

            if (!SteamAPIWrapper.Init())
            {
                MessageBox.Show("Please start steam first!");
                return;
            }
            // SteamWorkshop.StartCallbackService();

            // Load settings
            var settings = InitializeSettings();
            if (settings == null)
            {
                return;
            }

#if !DEBUG
            // Check for update
            if (settings.CheckForUpdates)
            {
                CheckForUpdate();
            }
#endif

            // clean up old files
            if (File.Exists(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak"))
            {
                // Restore backup
                File.Copy(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak", XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini", true);
                File.Delete(XCOM2.DefaultConfigDir + @"\DefaultModOptions.ini.bak");
            }

            Application.Run(new MainForm(settings));

            SteamAPIWrapper.Shutdown();
#if !DEBUG
        }

        catch (Exception e)
        {
            MessageBox.Show("An exception occured. See error.log for additional details.");
            File.WriteAllText("error.log", e.Message + "\r\nStack:\r\n" + e.StackTrace);
        }
#endif
        }