/// <summary>
        /// Reads a key from the Windows Registry.
        /// </summary>
        /// <returns>Registry Key Value or if it Doesn't Exist it Returns a String.Empty Value</returns>
        /// <param name="Key_Name">Registry Key Entry</param>
        /// <param name="Key_Path">Registry Key Path</param>
        public static string Read(string Key_Name, string Key_Path)
        {
            RegistryKey sk = null;

            try
            {
                sk = Registry.LocalMachine.OpenSubKey(Key_Path, false) ?? null;
                if (sk == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(sk.GetValue(Key_Name).ToString());
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("READ REGISTRYKEY", null, Error, null, true);
                return(string.Empty);
            }
            finally
            {
                if (sk != null)
                {
                    sk.Close();
                    sk.Dispose();
                }
            }
        }
        private static bool RequestIsGzipCompatible(NancyContext Context)
        {
            bool Status = false;

            try
            {
                if (Context.Request.Headers.AcceptEncoding != null)
                {
                    if (Context.Request.Headers.AcceptEncoding.Any(x => x.Contains("gzip")))
                    {
                        Status = true;
                    }
                    else if (Context.Request.Headers.AcceptEncoding.Any(x => x.Contains("deflate")))
                    {
                        Status = true;
                    }
                }

                if (EnableInsiderDeveloper.Allowed() && !Status)
                {
                    Log.Debug("Gzip Compatible? For " + Context.Request.Path + " " + Status);
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("RequestIsGzipCompatible", null, Error, null, true);
            }
            return(Status);
        }
Example #3
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs Error)
        {
            try
            {
                LogToFileAddons.OpenLog("Unhandled Exception", Translations.Database("Application_Exception_Unhandled") + ": ",
                                        (Exception)Error.ExceptionObject, "Error", false);

                try
                {
                    Process[] allOfThem = Process.GetProcessesByName("nfsw");
                    if (allOfThem != null && allOfThem.Any())
                    {
                        foreach (var oneProcess in allOfThem)
                        {
                            Process.GetProcessById(oneProcess.Id).Kill();
                        }
                    }
                }
                catch { }
            }
            finally
            {
                Application.Exit();
            }
        }
        /// <summary>
        /// Reads a key from the Windows Registry.
        /// </summary>
        /// <returns>Registry Key Value or if it Doesn't Exist it Returns a String.Empty Value</returns>
        /// <param name="Key_Name">Registry Key Entry</param>
        public static string Read(string Key_Name)
        {
            string subKey = Path.Combine("SOFTWARE", "Soapbox Race World", "Launcher");

            RegistryKey sk = null;

            try
            {
                sk = Registry.LocalMachine.OpenSubKey(subKey, false) ?? null;
                if (sk == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(sk.GetValue(Key_Name).ToString());
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("READ REGISTRYKEY", null, Error, null, true);
                return(string.Empty);
            }
            finally
            {
                if (sk != null)
                {
                    sk.Close();
                    sk.Dispose();
                }
            }
        }
Example #5
0
        public static void RecordEntry(string ID, string CAT, CommunicationLogEntryType TYPE, ICommunicationLogData DATA)
        {
            try
            {
                if (!Directory.Exists(Strings.Encode(Locations.LogCurrentFolder)))
                {
                    Directory.CreateDirectory(Strings.Encode(Locations.LogCurrentFolder));
                }
            }
            catch { }

            try
            {
                CommunicationLogEntry Entry = new CommunicationLogEntry
                {
                    ServerId   = ID,
                    Category   = CAT,
                    Data       = DATA,
                    Type       = CallMethod(TYPE),
                    RecordedAt = Time.GetTime("Now - UTC Time (Offset)")
                };

                File.AppendAllLines(Locations.LogCommunication, new List <string>
                {
                    JsonConvert.SerializeObject(Entry, Formatting.Indented)
                });
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Communication", null, Error, null, true);
            }
        }
Example #6
0
 public static String AsString(String File_Name)
 {
     if (string.IsNullOrWhiteSpace(File_Name))
     {
         return(String.Empty);
     }
     else
     {
         try
         {
             Assembly TheRun = Assembly.GetExecutingAssembly();
             using (Stream LiveStream = TheRun.GetManifestResourceStream(File_Name))
             {
                 if (LiveStream == null)
                 {
                     return(String.Empty);
                 }
                 else
                 {
                     using (StreamReader StreamViewer = new StreamReader(LiveStream))
                     {
                         return(StreamViewer.ReadToEnd());
                     }
                 }
             }
         }
         catch (Exception Error)
         {
             LogToFileAddons.OpenLog("Extract Resource AsString", null, Error, null, true);
             return(String.Empty);
         }
     }
 }
        public static string SecurityCenter(string caller)
        {
            string virusCheckerName = string.Empty;

            try
            {
                ManagementObjectSearcher   wmiData = new ManagementObjectSearcher(@"root\SecurityCenter2", "SELECT * FROM " + caller);
                ManagementObjectCollection data    = wmiData.Get();

                foreach (ManagementObject virusChecker in data)
                {
                    virusCheckerName = virusChecker["displayName"].ToString();
                    int status = Convert.ToInt32(virusChecker["productState"]);
                }
            }
            catch (ManagementException Error)
            {
                LogToFileAddons.OpenLog("Debug", null, Error, null, true);
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Debug", null, Error, null, true);
            }

            return(virusCheckerName);
        }
 private void SelectedGameServerToRemove()
 {
     if (ServerListRenderer.SelectedItems.Count == 1)
     {
         try
         {
             if (ServerListUpdater.NoCategoryList_CSO.Count > 0)
             {
                 if (MessageBox.Show(null, "Confirm to Remove " + ServerListBook[ServerListRenderer.SelectedIndices[0] + 1].Name + " from Saved Custom Servers",
                                     "GameLauncher", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                 {
                     ServerListUpdater.NoCategoryList_CSO.RemoveAt(ServerListRenderer.SelectedIndices[0]);
                     ServerListRenderer.Items.Remove(ServerListRenderer.SelectedItems[0]);
                     File.WriteAllText(Locations.LauncherCustomServers, JsonConvert.SerializeObject(ServerListUpdater.NoCategoryList_CSO));
                     Application.DoEvents();
                     GC.Collect();
                 }
             }
         }
         catch (Exception Error)
         {
             string LogMessage = "Failed to Remove Selected Server:";
             LogToFileAddons.OpenLog("Add Server", LogMessage, Error, null, false);
         }
     }
 }
Example #9
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(((LangObject)GameLangSource.SelectedItem).INI_Value))
            {
                FileSettingsSave.Lang         = ((LangObject)GameLangSource.SelectedItem).INI_Value;
                FileGameSettingsData.Language = ((LangObject)GameLangSource.SelectedItem).XML_Value;
            }

            try
            {
                if (((LangObject)GameLangSource.SelectedItem).Category == "Custom")
                {
                    /* Create Custom Settings.ini for LangPicker.asi module */
                    if (!Directory.Exists(FileSettingsSave.GameInstallation + "/scripts"))
                    {
                        Directory.CreateDirectory(FileSettingsSave.GameInstallation + "/scripts");
                    }

                    IniFile LanguagePickerFile = new IniFile(FileSettingsSave.GameInstallation + "/scripts/LangPicker.ini");
                    LanguagePickerFile.Write("Language", ((LangObject)GameLangSource.SelectedItem).INI_Value);
                    MessageBox.Show(null, "Please Note: If a Server does not provide a Language Pack, it will fallback to English instead.",
                                    "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (File.Exists(FileSettingsSave.GameInstallation + "/scripts/LangPicker.ini"))
                    {
                        File.Delete(FileSettingsSave.GameInstallation + "/scripts/LangPicker.ini");
                    }
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("WELCOME SCREEN", null, Error, null, true);
            }

            if (!string.IsNullOrWhiteSpace(((CDNList)CDNSource.SelectedItem).Url))
            {
                string ChoosenCDN = ((CDNList)CDNSource.SelectedItem).Url;
                string FinalCDNURL;

                if (ChoosenCDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    FinalCDNURL = ChoosenCDN.TrimEnd(charsToTrim);
                }
                else
                {
                    FinalCDNURL = ((CDNList)CDNSource.SelectedItem).Url;
                }

                SelectedCDN.CDNUrl = FinalCDNURL;

                QuitWithoutSaving_Click(sender, e);
            }
            else
            {
                MessageBox.Show(null, "Please Choose a CDN. \n\n(╯°□°)╯︵ ┻━┻", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #10
0
 public static byte[] AsByte(String File_Name)
 {
     if (string.IsNullOrWhiteSpace(File_Name))
     {
         return(null);
     }
     else
     {
         try
         {
             Assembly TheRun = Assembly.GetExecutingAssembly();
             using (Stream LiveStream = TheRun.GetManifestResourceStream(File_Name))
             {
                 if (LiveStream == null)
                 {
                     return(null);
                 }
                 else
                 {
                     byte[] ba = new byte[LiveStream.Length];
                     LiveStream.Read(ba, 0, ba.Length);
                     return(ba);
                 }
             }
         }
         catch (Exception Error)
         {
             LogToFileAddons.OpenLog("Extract Resource AsByte", null, Error, null, true);
             return(null);
         }
     }
 }
        private static bool ResponseIsCompatibleMimeType(NancyContext Context)
        {
            bool Status = false;

            try
            {
                if (Context.Response.ContentType != null)
                {
                    if (MimeTypes.Any(x => x == Context.Response.ContentType))
                    {
                        Status = true;
                    }
                    else if (MimeTypes.Any(x => Context.Response.ContentType.StartsWith($"{x};")))
                    {
                        Status = true;
                    }
                }

                if (EnableInsiderDeveloper.Allowed() && !Status)
                {
                    Log.Debug("Content Type? For " + Context.Request.Path + " " + Status);
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("ResponseIsCompatibleMimeType", null, Error, null, true);
            }
            return(Status);
        }
 public static void ThreadStatus(string ContinueThread)
 {
     try
     {
         if (ContinueThread == "Start" && !IsSplashScreenLive)
         {
             Log.Info("SPLASH SCREEN: Attempting to Start Thread");
             SplashScreenThread = new Thread(new ThreadStart(StartSplashScreen));
             SplashScreenThread.Start();
             Log.Info("SPLASH SCREEN: Thread has now Started");
         }
         else if (ContinueThread == "Stop" && IsSplashScreenLive)
         {
             Log.Info("SPLASH SCREEN: Attempting to Stop Thread");
             SplashScreenThread.Abort();
             Log.Completed("SPLASH SCREEN: Thread is now Stopped");
         }
         else
         {
             Log.Info("SPLASH SCREEN: Thread has already been Stopped");
         }
     }
     catch (Exception Error)
     {
         LogToFileAddons.OpenLog("SPLASH SCREEN", null, Error, null, true);
     }
 }
Example #13
0
        public static APIStatus CheckStatus(string URI, int Timer)
        {
            if (!string.IsNullOrWhiteSpace(URI))
            {
                HttpWebResponse ServerResponse = null;
                HttpWebRequest  URLConnection  = null;

                try
                {
                    Log.Checking("Checking Status: ".ToUpper() + URI);
                    Uri ConvertedAPIURI = new Uri(URI);
                    /* Releases Connection Socket after 30 seconds */
                    ServicePointManager.FindServicePoint(ConvertedAPIURI).ConnectionLeaseTimeout = (int)TimeSpan.FromSeconds(Timer + 1).TotalMilliseconds;
                    URLConnection = (HttpWebRequest)WebRequest.Create(ConvertedAPIURI);
                    URLConnection.AllowAutoRedirect = false; /* Find out if this site is up and don't follow a redirector */
                    URLConnection.Method            = "GET";
                    URLConnection.UserAgent         = "SBRW Launcher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)";
                    URLConnection.Timeout           = (int)TimeSpan.FromSeconds(Timer).TotalMilliseconds;
                    URLConnection.KeepAlive         = false;

                    try
                    {
                        ServerResponse = (HttpWebResponse)URLConnection.GetResponse();
                        Log.Completed("Checking Status: ".ToUpper() + URI + " [Is Online]");
                        return(APIStatus.Online);
                        /* Do something with response.Headers to find out information about the request */
                    }
                    catch (WebException Error)
                    {
                        Log.Completed("Checking Status: ".ToUpper() + URI + " [WebException]");
                        return(StatusCodes(URI, Error, (HttpWebResponse)Error.Response));
                    }
                }
                catch (Exception Error)
                {
                    Log.Completed("Checking Status: ".ToUpper() + URI + " [Exception]");
                    LogToFileAddons.OpenLog("API Checker", null, Error, null, true);
                    return(APIStatus.UnknownError);
                }
                finally
                {
                    if (ServerResponse != null)
                    {
                        ServerResponse.Close();
                        ServerResponse.Dispose();
                    }

                    if (URLConnection != null)
                    {
                        URLConnection.Abort();
                    }
                }
            }
            else
            {
                Log.Error("CORE: " + URI + " URI can not be Null!");
                return(APIStatus.Null);
            }
        }
Example #14
0
 public void WriteHashCache(string hashFileNameSuffix, bool writeOldHashes)
 {
     lock (this._fileList)
     {
         FileStream   fileStream   = null;
         CryptoStream cryptoStream = null;
         StreamWriter streamWriter = null;
         try
         {
             try
             {
                 fileStream = new FileStream(string.Concat("HashFile", hashFileNameSuffix), FileMode.Create);
                 DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
                 byte[] bytes    = Encoding.ASCII.GetBytes("12345678");
                 byte[] numArray = bytes;
                 dESCryptoServiceProvider.IV  = bytes;
                 dESCryptoServiceProvider.Key = numArray;
                 cryptoStream = new CryptoStream(fileStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
                 streamWriter = new StreamWriter(cryptoStream);
                 foreach (string key in this._fileList.Keys)
                 {
                     string empty = string.Empty;
                     empty = (!writeOldHashes ? this._fileList[key].New : this._fileList[key].Old);
                     if (!File.Exists(key) || string.IsNullOrWhiteSpace(empty))
                     {
                         continue;
                     }
                     DateTime lastWriteTime = (new FileInfo(key)).LastWriteTime;
                     streamWriter.WriteLine(string.Format("{0}\t{1}\t{2}", key, empty, lastWriteTime.Ticks));
                 }
             }
             catch (Exception Error)
             {
                 LogToFileAddons.OpenLog("CDN DOWNLOADER [Write Hash Cache]", null, Error, null, true);
                 Exception exception = Error;
             }
         }
         finally
         {
             if (streamWriter != null)
             {
                 streamWriter.Close();
                 streamWriter.Dispose();
             }
             if (cryptoStream != null)
             {
                 cryptoStream.Close();
                 cryptoStream.Dispose();
             }
             if (fileStream != null)
             {
                 fileStream.Close();
                 fileStream.Dispose();
             }
         }
     }
 }
Example #15
0
 /// <summary>
 /// Retrieves the return value of the asynchronous operation represented by the System.IAsyncResult passed.
 /// </summary>
 /// <typeparam name="T">Controls Value</typeparam>
 /// <param name="this">Name of the Control</param>
 /// <param name="Invoke_Result">The System.IAsyncResult that represents a specific invoke asynchronous operation,
 /// returned when calling System.Windows.Forms.Control.BeginInvoke(System.Delegate).</param>
 /// <returns>The System.Object generated by the asynchronous operation.</returns>
 static public void SafeEndInvokeAsyncCatch <T>(this T @this, IAsyncResult Invoke_Result) where T : Control
 {
     try
     {
         @this.EndInvoke(Invoke_Result);
     }
     catch (Exception Error)
     {
         LogToFileAddons.OpenLog("Safe Invoker [End Invoke (Singleton)]", null, Error, null, true);
     }
 }
        private TextResponse OnError(NancyContext context, Exception Error)
        {
            Log.Error("PROXY HANDLER: " + context.Request.Path);
            LogToFileAddons.OpenLog("PROXY HANDLER", null, Error, null, true);

            CommunicationLog.RecordEntry(ServerProxy.Instance.GetServerName(), "PROXY", CommunicationLogEntryType.Error,
                                         new CommunicationLogLauncherError(Error.Message, context.Request.Path, context.Request.Method));

            context.Request.Dispose();

            return(new TextResponse(HttpStatusCode.BadRequest, Error.Message));
        }
Example #17
0
            public static string SysMem()
            {
                long memKb = 0;

                try
                {
                    Kernel32.GetPhysicallyInstalledSystemMemory(out memKb);
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("Hardware Info", null, Error, null, true);
                }
                return((memKb / 1024).ToString());
            }
        private static bool ContentLengthIsTooSmall(NancyContext Context)
        {
            try
            {
                if (Context.Response.Headers == null)
                {
                    if (EnableInsiderDeveloper.Allowed())
                    {
                        Log.Debug("Headers is Null for " + Context.Request.Path);
                    }
                    return(true);
                }
                else
                {
                    if (!Context.Response.Headers.TryGetValue("Content-Length", out string ContentLength))
                    {
                        using (MemoryStream mm = new MemoryStream())
                        {
                            Context.Response.Contents.Invoke(mm);
                            mm.Flush();
                            ContentLength = mm.Length.ToString();
                        }
                    }
                    if (EnableInsiderDeveloper.Allowed())
                    {
                        Log.Debug($"GZip Content-Length of response is {ContentLength} for {Context.Request.Path}");
                    }

                    /* Wine Mono is Unable to Allow the Game to Continue compared to its Windows CounterPart */
                    if (long.Parse(ContentLength) > 0 || UnixOS.Detected())
                    {
                        return(false);
                    }
                    else
                    {
                        if (EnableInsiderDeveloper.Allowed())
                        {
                            Log.Debug($"GZip Content-Length is too small for {Context.Request.Path}");
                        }
                        return(true);
                    }
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("ContentLengthIsTooSmall", null, Error, null, true);
                return(true);
            }
        }
Example #19
0
            public static string CPUName()
            {
                string _cpuName = "Unknown";

                try
                {
                    _cpuName = (from x in new ManagementObjectSearcher("SELECT Name FROM Win32_Processor").Get().Cast <ManagementObject>()
                                select x.GetPropertyValue("Name")).FirstOrDefault().ToString();
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("Hardware Info", null, Error, null, true);
                }
                return(_cpuName);
            }
Example #20
0
 /// <summary>
 /// Executes the specified delegate on the thread that owns the control's underlying window handle.
 /// </summary>
 /// <returns>The delegate being invoked has no return value.</returns>
 /// <param name="Control_Form">Name of the Control</param>
 /// <param name="Action_Refresh">Parameters to be set for this Control</param>
 /// <param name="Window_Name">Name of the Parent Form</param>
 static public void SafeInvokeAction(this Control Control_Form, Action Action_Refresh, Form Window_Name)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(Window_Name.Name))
         {
             if (!(Application.OpenForms[Window_Name.Name] != null ? Application.OpenForms[Window_Name.Name].Disposing : true) && !Application.OpenForms[Window_Name.Name].IsDisposed)
             {
                 if (!Control_Form.IsDisposed || (Control_Form.IsHandleCreated && Control_Form.FindForm().IsHandleCreated))
                 {
                     if (!Control_Form.Disposing)
                     {
                         if (Control_Form.InvokeRequired)
                         {
                             Control_Form.Invoke(Action_Refresh);
                         }
                         else
                         {
                             Action_Refresh();
                         }
                     }
                     else
                     {
                         Log.Function("SafeInvokeAction".ToUpper() + "Control: " + Control_Form.Name + " is being Disposed");
                     }
                 }
                 else if (!Application.OpenForms[Window_Name.Name].IsDisposed)
                 {
                     Window_Name.Controls.Add(Control_Form);
                     SafeInvokeAction(Control_Form, Action_Refresh);
                     Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form.Name + " was added to the Form: " + Window_Name.Name);
                 }
                 else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed())
                 {
                     Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " <- Handle hasn't been Created or has been Disposed | Action: " + Action_Refresh + " Form: " + Window_Name);
                 }
             }
         }
         else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed())
         {
             Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " Action: " + Action_Refresh + " Form: " + Window_Name + " <- Is Null");
         }
     }
     catch (Exception Error)
     {
         LogToFileAddons.OpenLog("Safe Invoker Action", null, Error, null, true);
     }
 }
Example #21
0
 private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs args)
 {
     while (true)
     {
         lock (DownloaderHashReader._queueHashLock)
         {
             if (this._queueHash.Count == 0)
             {
                 DownloaderHashReader._workerCount--;
                 break;
             }
         }
         string str = null;
         lock (DownloaderHashReader._queueHashLock)
         {
             str = this._queueHash.Dequeue();
         }
         string base64String = null;
         if (File.Exists(str))
         {
             if (string.IsNullOrWhiteSpace(this._fileList[str].Old))
             {
                 try
                 {
                     using (FileStream fileStream = File.OpenRead(str))
                     {
                         using (MD5 mD5 = MD5.Create())
                         {
                             base64String = Convert.ToBase64String(mD5.ComputeHash(fileStream));
                         }
                     }
                 }
                 catch (Exception Error)
                 {
                     LogToFileAddons.OpenLog("CDN DOWNLOADER [Background]", null, Error, null, true);
                 }
             }
             else
             {
                 base64String = this._fileList[str].Old;
             }
         }
         lock (this._fileList[str])
         {
             this._fileList[str].Old = base64String;
         }
     }
 }
        public static bool Signed(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                Log.Error("SIGNED: File Path cannot be Null");
            }
            else
            {
                try
                {
                    var File = new WINTRUST_FILE_INFO
                    {
                        cbStruct      = Marshal.SizeOf(typeof(WINTRUST_FILE_INFO)),
                        pcwszFilePath = filePath
                    };

                    var Data = new WINTRUST_DATA
                    {
                        cbStruct            = Marshal.SizeOf(typeof(WINTRUST_DATA)),
                        dwUIChoice          = WTD_UI_NONE,
                        dwUnionChoice       = WTD_CHOICE_FILE,
                        fdwRevocationChecks = WTD_REVOKE_NONE,
                        pFile = Marshal.AllocHGlobal(File.cbStruct)
                    };
                    Marshal.StructureToPtr(File, Data.pFile, false);

                    int hr;
                    try
                    {
                        hr = WinVerifyTrust(INVALID_HANDLE_VALUE, WINTRUST_ACTION_GENERIC_VERIFY_V2, ref Data);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(Data.pFile);
                    }

                    return(hr == 0);
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("SIGNED", null, Error, null, true);
                    return(false);
                }
            }

            return(false);
        }
Example #23
0
        /* Searches for Installed Windows Updates */
        public static bool GetInstalledHotFix(string identification)
        {
            if (!UnixOS.Detected())
            {
                ManagementObjectSearcher   ObjectPath       = null;
                ManagementObjectCollection ObjectCollection = null;

                try
                {
                    ObjectPath       = new ManagementObjectSearcher("SELECT HotFixID FROM Win32_QuickFixEngineering");
                    ObjectCollection = ObjectPath.Get();

                    foreach (ManagementBaseObject SearchBase in ObjectCollection)
                    {
                        if (SearchBase.Properties["HotFixID"].Value.ToString() == identification)
                        {
                            return(true);
                        }
                    }
                }
                catch (ManagementException Error)
                {
                    LogToFileAddons.OpenLog("Installed KB [M.E.]", null, Error, null, true);
                }
                catch (COMException Error)
                {
                    LogToFileAddons.OpenLog("Installed KB [C.O.M.]", null, Error, null, true);
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("Installed KB", null, Error, null, true);
                }
                finally
                {
                    if (ObjectPath != null)
                    {
                        ObjectPath.Dispose();
                    }
                    if (ObjectCollection != null)
                    {
                        ObjectCollection.Dispose();
                    }
                }
            }

            return(false);
        }
Example #24
0
        /* Server Name */

        /** Returns a Server Name by first checking if the Server has provided one
         *  if so use that, otherwise it will see if the ServerList has provide one
         *  if not then it will see if its a custom server, which will provide "Custom"
         *  otherwise it will be "uknown" **/
        public static string ServerName(string State)
        {
            try
            {
                if (InformationCache.SelectedServerJSON != null &&
                    !string.IsNullOrWhiteSpace(InformationCache.SelectedServerJSON.serverName))
                {
                    return(InformationCache.SelectedServerJSON.serverName);
                }
                else if (InformationCache.SelectedServerData != null &&
                         !string.IsNullOrWhiteSpace(InformationCache.SelectedServerData.Name))
                {
                    return(InformationCache.SelectedServerData.Name);
                }
                else
                {
                    switch (State)
                    {
                    case "Register":
                    case "RPC":
                        return("Custom Server");

                    case "Settings":
                        return("The Selected Server");

                    case "Select Server":
                        if (SelectServer.ServerJsonData != null &&
                            !string.IsNullOrWhiteSpace(SelectServer.ServerJsonData.serverName))
                        {
                            return(SelectServer.ServerJsonData.serverName);
                        }
                        else
                        {
                            return(SelectServer.ServerName);
                        }

                    default:
                        return("Custom");
                    }
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Server Name Provider", null, Error, null, true);
                return("Unknown");
            }
        }
        public static int Platform()
        {
            try
            {
                if (CachedNumPlatform == 2020)
                {
                    CachedNumPlatform = (int)Environment.OSVersion.Platform;
                }

                return(CachedNumPlatform);
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Unix Platform Detection", null, Error, null, true);
                return(CachedNumPlatform);
            }
        }
Example #26
0
            public static string DriverVersion()
            {
                string _driverVersion = "Unknown";

                try
                {
                    _driverVersion = (from x in new ManagementObjectSearcher("select * from Win32_VideoController").Get()
                                      .Cast <ManagementObject>()
                                      select x.GetPropertyValue("DriverVersion")).FirstOrDefault().ToString();
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("Hardware Info", null, Error, null, true);
                }

                return(_driverVersion);
            }
Example #27
0
 public static bool ValidJson(string strInput)
 {
     if (string.IsNullOrWhiteSpace(strInput))
     {
         return(false);
     }
     else
     {
         try
         {
             strInput = strInput.Trim();
             if ((strInput.StartsWith("{") && strInput.EndsWith("}")) || /* For object */
                 (strInput.StartsWith("[") && strInput.EndsWith("]")))   /* For array */
             {
                 try
                 {
                     var obj = JToken.Parse(strInput);
                     return(true);
                 }
                 catch (JsonReaderException Error)
                 {
                     /* Exception in parsing json */
                     LogToFileAddons.OpenLog("VALID JSON", null, Error, null, true);
                     return(false);
                 }
                 catch (Exception Error)
                 {
                     /* General Exception */
                     LogToFileAddons.OpenLog("VALID JSON", null, Error, null, true);
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception Error)
         {
             LogToFileAddons.OpenLog("VALID JSON", null, Error, null, true);
             return(false);
         }
     }
 }
        public static string Database(string Text_Request)
        {
            if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed())
            {
                Log.Function("DATABASE: Requested: " + Text_Request + " Lang: " + Application_Language);
            }

            try
            {
                if (Lang_Launcher == null || ResetCache)
                {
                    switch (UI(Application_Language))
                    {
                    default:
                        Lang_Launcher = new ResourceManager("GameLauncher.App.Languages.English_Texts", Assembly.GetExecutingAssembly());
                        break;
                    }

                    ResetCache = false;
                }

                try
                {
                    if (!string.IsNullOrWhiteSpace(Text_Request) && Lang_Launcher != null)
                    {
                        return(Regex.Unescape(Lang_Launcher.GetString(Text_Request)));
                    }
                    else
                    {
                        return("Languages Programer ERROR");
                    }
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("Translations Database Selection", null, Error, null, true);
                    return("Languages Program ERROR");
                }
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Translations Database", null, Error, null, true);
                return("Languages ERROR");
            }
        }
Example #29
0
        public static string EstimateFinishTime(long current, long total, DateTime keyValue)
        {
            try
            {
                var num = current / (double)total;
                if (num < 0.00185484899838312)
                {
                    return("Calculating");
                }

                var now      = DateTime.Now - keyValue;
                var timeSpan = TimeSpan.FromTicks((long)(now.Ticks / num)) - now;

                int rDays    = Convert.ToInt32(timeSpan.Days.ToString()) + 1;
                int rHours   = Convert.ToInt32(timeSpan.Hours.ToString()) + 1;
                int rMinutes = Convert.ToInt32(timeSpan.Minutes.ToString()) + 1;
                int rSeconds = Convert.ToInt32(timeSpan.Seconds.ToString()) + 1;

                if (rDays > 1)
                {
                    return(rDays.ToString() + " days remaining");
                }
                if (rHours > 1)
                {
                    return(rHours.ToString() + " hours remaining");
                }
                if (rMinutes > 1)
                {
                    return(rMinutes.ToString() + " minutes remaining");
                }
                if (rSeconds > 1)
                {
                    return(rSeconds.ToString() + " seconds remaining");
                }

                return("Just now");
            }
            catch (Exception Error)
            {
                LogToFileAddons.OpenLog("Estimate Finish Time", null, Error, null, true);
                return("N/A");
            }
        }
Example #30
0
 /// <summary>Opens the Form. If the Form is already Open it will Give it Foucus</summary>
 public static void OpenScreen()
 {
     if (IsAddServerOpen || Application.OpenForms["AddServer"] != null)
     {
         if (Application.OpenForms["AddServer"] != null)
         {
             Application.OpenForms["AddServer"].Activate();
         }
     }
     else
     {
         try { new AddServer().ShowDialog(); }
         catch (Exception Error)
         {
             string ErrorMessage = "Add Server Screen Encountered an Error";
             LogToFileAddons.OpenLog("Add Server Screen", ErrorMessage, Error, "Exclamation", false);
         }
     }
 }