Exemple #1
0
        /// <summary>
        /// Saves the settings that has been modified during runtime
        /// Should be called when the program is exited
        /// It will first compare and see if the current file is the same as when the program was started
        /// If it's not then it will make a copy of the file and then overwrite it, if the user has modified
        /// the file during runtime
        /// </summary>
        /// <param name="oldSettings">Old settings</param>
        /// <param name="newSettings">New settings</param>
        /// <returns>Returns true if succeeded</returns>
        public static bool UpdateSettings(Config.Settings oldSettings, Config.Settings newSettings)
        {
            try
            {
                /*Now we'll go through all accounts and make sure we don't print out their password to the file
                 * if no password was originally set in the settings file*/
                foreach (var oldAcc in oldSettings.Accounts)
                {
                    if (!string.IsNullOrWhiteSpace(oldAcc.Details.Password))
                    {
                        continue;
                    }

                    foreach (var newAcc in newSettings.Accounts)
                    {
                        if (oldAcc.Details.Username == newAcc.Details.Username)
                        {
                            newAcc.Details.Password = string.Empty;
                        }
                    }
                }

                /*Now we'll overwrite the settings file with the new settings content*/
                File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(newSettings, Formatting.Indented));
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error updating settings file\n{ex.Message}");
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Reads the settings from file
        /// </summary>
        /// <returns>Returns false if failed</returns>
        static private bool ReadSettings()
        {
            /*Load settings if file exists, else create one*/
            string filePath = Path.Combine(Application.StartupPath, "Settings.json");

            if (!File.Exists(filePath))
            {
                /*Set up settings class to print*/
                Config.Settings settings = new Config.Settings();

                /*Add example accounts*/
                var tempacc = new Config.AccountInfo();
                tempacc.SetTemporaryValues();
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);

                /*Write settings to file*/
                string settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented);
                File.WriteAllText(filePath, settingsJson);
                Console.WriteLine("Settings.json has been written. Edit it for your accounts.");
                Thread.Sleep(1500);
            }
            else
            {
                /*Enable missing objects error*/
                JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
                jsonSettings.MissingMemberHandling = MissingMemberHandling.Error;
                string settingsJson = string.Empty;

                try
                {
                    /*Load the settings from file*/
                    settingsJson = File.ReadAllText(filePath);
                    mSettings    = JsonConvert.DeserializeObject <Config.Settings>(settingsJson, jsonSettings);

                    /*Write the class to settins file incase some of the settings were missing from the file originally*/
                    File.WriteAllText(filePath, JsonConvert.SerializeObject(mSettings, Formatting.Indented));
                    return(true);
                }
                catch (JsonReaderException ex)
                {
                    /*There was an error parsing the json file, most likely due to user trying to manually edit it without knowing the syntax*/
                    Console.WriteLine("Error: The settings file is corrupt. Please delete it and restart the program.");
                    Console.WriteLine($"{ex.Message}\n\n");
                }
                catch (Exception ex)
                {
                    /*I wonder what happened here?*/
                    Console.WriteLine("Error: An unhandled exception occured when parsing the settings? What the hell?");
                    Console.WriteLine($"{ex.Message}\n\n");
                }
            }

            Console.WriteLine("Exiting in 10 seconds...");
            Thread.Sleep(10000);
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Read the settings for the application
        /// </summary>
        /// <returns></returns>
        public static Config.Settings GetSettings()
        {
            if (!File.Exists(EndPoint.SETTINGS_FILE_PATH))
            {
                var settings = new Config.Settings()
                {
                    Accounts = new List <Config.AccountSettings>()
                    {
                        new Config.AccountSettings()
                        {
                            Games = new List <int>()
                            {
                                730, 10
                            }
                        },
                        new Config.AccountSettings()
                        {
                            Games = new List <int>()
                            {
                                730, 10
                            }
                        },
                        new Config.AccountSettings()
                        {
                            Games = new List <int>()
                            {
                                730, 10
                            }
                        }
                    }
                };

                File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
                Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}\nPlease close the program and edit the settings.");
            }
            else
            {
                var serializeSettings = new JsonSerializerSettings()
                {
                    MissingMemberHandling = MissingMemberHandling.Error
                };
                try
                {
                    var settings = JsonConvert.DeserializeObject <Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
                    settings.Accounts = settings.Accounts.Where(o => !string.IsNullOrWhiteSpace(o.Details.Username)).Distinct().ToList();

                    return(settings);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error reading settings file\n{ex.Message}");
                }
            }

            Thread.Sleep(1500);
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="settings"></param>
        public Session(Config.Settings settings)
        {
            mSettings = settings;

            if (settings.CheckForUpdates && Update.IsUpdateAvailable())
            {
                Console.WriteLine("There's an update available. Check out https://github.com/Ezzpify/HourBoostr/releases/latest");
            }

            mBwg.DoWork += MBwg_DoWork;
            mBwg.RunWorkerAsync();
        }
Exemple #5
0
        /// <summary>
        /// Main function
        /// Too many comments
        /// </summary>
        /// <param name="args">No args</param>
        static void Main(string[] args)
        {
            /*Create a folder for our account sentry files*/
            Console.Title = EndPoint.CONSOLE_TITLE;
            Directory.CreateDirectory(EndPoint.SENTRY_FOLDER_PATH);
            Directory.CreateDirectory(EndPoint.LOG_FOLDER_PATH);

            /*Set exit events so we'll log out all accounts if application is exited*/
            mEventHandler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(mEventHandler, true);

            /*Start the trayicon thread*/
            mThreadTray = new Thread(ToTray);
            mThreadTray.Start();

            /*We'll read and store the settings twice since we'll compare the two objects later on
             * to see if something has changed by the user during runtime*/
            mSettings = Settings.GetSettings();
            if (mSettings == null)
            {
                return;
            }

            /*Read the application settings and start our session*/
            var settings = Settings.GetSettings();

            if (settings != null)
            {
                if (settings.Accounts.Count > 0)
                {
                    mSession = new Session(settings);
                    while (mSession.mBwg.IsBusy)
                    {
                        Thread.Sleep(250);
                    }

                    if (settings.HideToTrayAutomatically)
                    {
                        mTrayIcon.ShowBalloonTip(1000, "HourBoostr", "I'm down here!", ToolTipIcon.Info);
                        ShowConsole(false);
                    }
                }
                else
                {
                    Console.WriteLine("No accounts were loaded from settings.");
                }

                while (true)
                {
                    Thread.Sleep(250);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="settings"></param>
        public Session(Config.Settings settings)
        {
            mSettings = settings;

            if (settings.CheckForUpdates && Update.IsUpdateAvailable())
            {
                var diagResult = MessageBox.Show("There seems to be an update available.\nCheck it out?", "Update", MessageBoxButtons.YesNo);
                if (diagResult == DialogResult.Yes)
                {
                    Process.Start("https://github.com/Ezzpify/HourBoostr/releases/latest");
                }
            }

            mBwg.DoWork += MBwg_DoWork;
            mBwg.RunWorkerAsync();
        }
Exemple #7
0
        /// <summary>
        /// Main initializer for each account
        /// </summary>
        /// <param name="info">Account info</param>
        public Bot(Config.AccountInfo info, Config.Settings settings)
        {
            /*If a password isn't set we'll ask for user input*/
            if (string.IsNullOrEmpty(info.Password))
            {
                Console.WriteLine("Enter password for account '{0}'", info.Username);
                info.Password = Password.ReadPassword();
            }

            /*Assign bot info*/
            mSteam.loginDetails = new SteamUser.LogOnDetails()
            {
                Username = info.Username,
                Password = info.Password,
                ShouldRememberPassword = true
            };
            mInfo             = info;
            mSettings         = settings;
            mSteam.games      = info.Games;
            mSteam.sentryPath = Path.Combine(Application.StartupPath, string.Format("Sentryfiles\\{0}.sentry", info.Username));

            /*Assign clients*/
            mSteam.client          = new SteamClient();
            mSteam.callbackManager = new CallbackManager(mSteam.client);
            mSteam.user            = mSteam.client.GetHandler <SteamUser>();
            mSteam.friends         = mSteam.client.GetHandler <SteamFriends>();

            /*Subscribe to Callbacks*/
            mSteam.callbackManager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            mSteam.callbackManager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            mSteam.callbackManager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            mSteam.callbackManager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
            mSteam.callbackManager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey);

            /*Connect to Steam*/
            Connect();

            /*Start Callback thread*/
            mBotThread = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            mBotThread.DoWork             += BackgroundWorkerOnDoWork;
            mBotThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted;
            mBotThread.RunWorkerAsync();
        }
Exemple #8
0
        /// <summary>
        /// Reads the settings from file
        /// </summary>
        /// <returns>Returns false if failed</returns>
        static private bool ReadSettings()
        {
            /*Load settings if file exists, else create one*/
            string filePath = Path.Combine(Application.StartupPath, "Settings.json");

            if (!File.Exists(filePath))
            {
                /*Set up settings class to print*/
                Config.Settings settings = new Config.Settings();

                /*Add example accounts*/
                var tempacc = new Config.AccountInfo();
                tempacc.SetTemporaryValues();
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);

                /*Write settings to file*/
                string settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented);
                File.WriteAllText(filePath, settingsJson);
                Console.WriteLine("Settings.json has been written. Edit it for your accounts.");
                Thread.Sleep(1500);
            }
            else
            {
                try
                {
                    /*Load the settings from file*/
                    string settingsJson = File.ReadAllText(filePath);
                    mSettings = JsonConvert.DeserializeObject <Config.Settings>(settingsJson);
                    return(true);
                }
                catch (JsonException jex)
                {
                    /*User f****d up with the formatting probably*/
                    MessageBox.Show("There was an error parsing Settings.json\n"
                                    + "It's either incorrectly formatted or corrupt.\n"
                                    + "Delete the file and let the app make a new one.\n\nError: " + jex.Message);
                }
            }

            return(false);
        }
Exemple #9
0
        /// <summary>
        /// Main initializer for each account
        /// </summary>
        /// <param name="info">Account info</param>
        public BotClass(Config.AccountInfo info, Config.Settings settings)
        {
            /*If a password isn't set we'll ask for user input*/
            if (string.IsNullOrEmpty(info.Password))
            {
                Console.WriteLine("Enter password for account '{0}'", info.Username);
                info.Password = Password.ReadPassword();
            }

            /*Assign bot info*/
            mSteam.loginDetails = new SteamUser.LogOnDetails()
            {
                Username = info.Username,
                Password = info.Password
            };
            mInfo = info;
            mSettings = settings;
            mSteam.games = info.Games;
            mSteam.sentryPath = Path.Combine(Application.StartupPath, string.Format("Sentryfiles\\{0}.sentry", info.Username));

            /*Assign clients*/
            mSteam.client = new SteamClient();
            mSteam.callbackManager = new CallbackManager(mSteam.client);
            mSteam.user = mSteam.client.GetHandler<SteamUser>();
            mSteam.friends = mSteam.client.GetHandler<SteamFriends>();

            /*Assign Callbacks*/
            new Callback<SteamClient.ConnectedCallback>(OnConnected, mSteam.callbackManager);
            new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, mSteam.callbackManager);
            new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, mSteam.callbackManager);
            new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, mSteam.callbackManager);

            /*Connect to Steam*/
            Print("Connecting to steam ...", info.Username);
            mSteam.client.Connect();

            /*Start Callback thread*/
            mThreadCallback = new Thread(RunCallback);
            mThreadCallback.Start();
        }
Exemple #10
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="settings"></param>
 public Session(Config.Settings settings)
 {
     mSettings = settings;
     DoWork();
 }
Exemple #11
0
 /// <summary>
 /// Writes settings to file
 /// </summary>
 /// <param name="settings">Settings object</param>
 /// <returns>Return true. Lol.</returns>
 public static bool SaveSettings(Config.Settings settings)
 {
     File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
     return(true);
 }