/// <summary> /// Writes an error to the errorlog.txt /// </summary> /// <param name="ex">The occured exception</param> /// <param name="message">A short message i.e "Error while loading reminders"</param> /// <param name="showErrorPopup">true to pop up an additional windows form to show the user that an error has occured</param> /// <param name="sendToOnlineDatabase">Determines wether WriteError() is allowed to send the error to the online database this is true by default</param> public static void WriteError(Exception ex, string message, bool sendToOnlineDatabase = true) { new Thread(() => { try { //The bunifu framework makes a better looking ui, but it also throws annoying null reference exceptions when disposing an form/usercontrol //that has an bunifu control in it(like a button), while there shouldn't be an exception. if ((ex is System.Runtime.InteropServices.ExternalException) && ex.Source == "System.Drawing" && ex.Message.Contains("GDI+")) { return; } if (sendToOnlineDatabase && HasInternetAccess()) { BLOnlineDatabase.AddException(ex, DateTime.Now, IOVariables.systemLog); } else { //Only write to the errorlog.txt if writing to the database failed, since we insert the errorlog into the database //at a different time when above doesn't fail using (FileStream fs = new FileStream(IOVariables.errorLog, FileMode.Append)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("[" + DateTime.Now + "] - " + message + Environment.NewLine + ex.ToString() + Environment.NewLine + Environment.NewLine); } Log("EXCEPTION -> " + ex.GetType().ToString() + " -> \"" + message + "\"" + "\r\n" + ex.ToString()); } } catch { } }).Start(); }
/// <summary> /// Writes an unique string to string.txt in the RemindMe folder if it does not exists /// </summary> public static void WriteUniqueString() { new Thread(() => { if (!HasInternetAccess()) { return; } Settings set = BLLocalDatabase.Setting.Settings; try { //Change a 200-character string to a 10 character string. saves db space and 200 is just unnecesary if (set.UniqueString != null && set.UniqueString.Length == 200) { string uniqueStringOld = set.UniqueString; set.UniqueString = GenerateString(); while (!BLOnlineDatabase.IsUniqueString(set.UniqueString)) { set.UniqueString = GenerateString(); } DLOnlineDatabase.TransformUniqueString(uniqueStringOld, set.UniqueString, IOVariables.RemindMeVersion); } else if (string.IsNullOrWhiteSpace(set.UniqueString)) { string uniqueString = GenerateString(); Log("No unique string detected. Generated unique string."); while (!BLOnlineDatabase.IsUniqueString(uniqueString)) { //This shouldn't even happen, because the likelihood is insanely small, but hey, if it does happen, generate a new ID Log("unique string NOT unique. generating new id..."); uniqueString = GenerateString(); } set.UniqueString = uniqueString; } else { Log("WriteUniqueString() ignored."); } } catch (Exception ex) { Log("WriteUniqueString failed -> " + ex.GetType().ToString()); WriteError(ex, "WriteUniqueString failed -> " + ex.GetType().ToString(), true); } BLLocalDatabase.Setting.UpdateSettings(set); }).Start(); }