/// <summary>
        /// Updates the masterlist at the given path.
        /// </summary>
        public void UpdateMasterlist()
        {
            if (MasterlistHasUpdate())
            {
                bool   booExist     = File.Exists(MasterlistPath);
                bool   booUpdated   = false;
                UInt32 uintStatus   = 0;
                string strDirectory = Path.GetDirectoryName(MasterlistPath);
                if (!Directory.Exists(strDirectory))
                {
                    Directory.CreateDirectory(strDirectory);
                }
                try
                {
                    string remoteUrl    = String.Format("https://github.com/loot/{0}.git", GameMode.ModeId);
                    string remoteBranch = "master";

                    uintStatus = m_dlgUpdateMasterlist(m_ptrSorterDb, MasterlistPath, remoteUrl, remoteBranch, ref booUpdated);
                }
                catch (SorterException e)
                {
                    Trace.TraceWarning("GamebryoBase.PluginSorter.UpdateMasterlist() - Encountered an ignored SorterException.");
                    TraceUtil.CreateTraceExceptionString(e);
                }
                catch (AccessViolationException e)
                {
                    Trace.TraceWarning("GamebryoBase.PluginSorter.UpdateMasterlist() - Encountered an ignored AccessViolationException.");
                    TraceUtil.TraceException(e);
                }

                HandleStatusCode(uintStatus);

                if (booExist && booUpdated)
                {
                    EvaluateMasterlist();
                }
                else if (booUpdated)
                {
                    Load(MasterlistPath, UserlistPath);
                }
            }
        }
        /// <summary>
        /// Updates the masterlist at the given path.
        /// </summary>
        /// <returns><c>true</c> if an update to the masterlist is available;
        /// <c>false</c> otherwise.</returns>
        public bool MasterlistHasUpdate()
        {
            UInt32 uintStatus        = 0;
            bool   booRequiresUpdate = false;
            string remoteBranch      = "master";

            try
            {
                string remoteUrl = String.Format("https://github.com/loot/{0}.git", GameMode.ModeId);
                uintStatus = m_dlgUpdateMasterlist(m_ptrSorterDb, MasterlistPath, remoteUrl, remoteBranch, ref booRequiresUpdate);
            }
            catch (SorterException e)
            {
                Trace.TraceWarning("GamebryoBase.PluginSorter.MasterlistHasUpdate() - Encountered an ignored SorterException.");
                TraceUtil.CreateTraceExceptionString(e);
            }
            catch (AccessViolationException e)
            {
                Trace.TraceWarning("GamebryoBase.PluginSorter.MasterlistHasUpdate() - Encountered an ignored AccessViolationException.");
                TraceUtil.TraceException(e);
            }

            return(booRequiresUpdate);
        }
Exemple #3
0
        /// <summary>
        /// This lets the user know a problem has occurred, and logs the exception.
        /// </summary>
        /// <param name="ex">The exception that is being handled.</param>
        private static void HandleException(Exception ex)
        {
            HeaderlessTextWriterTraceListener htlListener = (HeaderlessTextWriterTraceListener)Trace.Listeners["DefaultListener"];
            DialogResult drResult = DialogResult.No;

            Trace.WriteLine("");
            Trace.TraceError("Tracing an Unhandled Exception:");
            TraceUtil.TraceException(ex);

            if (!htlListener.TraceIsForced)
            {
                htlListener.SaveToFile();
            }

            StringBuilder stbPromptMessage = new StringBuilder();

            stbPromptMessage.AppendFormat("{0} has encountered an error and needs to close.", EnvironmentInfo.Settings.ModManagerName).AppendLine();
            stbPromptMessage.AppendLine("A Trace Log file was created at:");
            stbPromptMessage.AppendLine(htlListener.FilePath);
            stbPromptMessage.AppendLine("Before reporting the issue, don't close this window and check for a fix here (you can close it afterwards):");
            stbPromptMessage.AppendLine(NexusLinks.FAQs);
            stbPromptMessage.AppendLine("If you can't find a solution, please make a bug report and attach the TraceLog file here:");
            stbPromptMessage.AppendLine(NexusLinks.Issues);
            stbPromptMessage.AppendLine(Environment.NewLine + "Do you want to open the TraceLog folder?");
            try
            {
                //the extended message box contains an activex control wich must be run in an STA thread,
                // we can't control what thread this gets called on, so create one if we need to
                string      strException   = "The following information is in the Trace Log:" + Environment.NewLine + TraceUtil.CreateTraceExceptionString(ex);
                ThreadStart actShowMessage = () => drResult = ExtendedMessageBox.Show(null, stbPromptMessage.ToString(), "Error", strException, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                ApartmentState astState = ApartmentState.Unknown;
                Thread.CurrentThread.TrySetApartmentState(astState);
                if (astState == ApartmentState.STA)
                {
                    actShowMessage();
                }
                else
                {
                    Thread thdMessage = new Thread(actShowMessage);
                    thdMessage.SetApartmentState(ApartmentState.STA);
                    thdMessage.Start();
                    thdMessage.Join();
                    if (drResult == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process prc = new System.Diagnostics.Process();
                            prc.StartInfo.FileName = Path.GetDirectoryName(htlListener.FilePath);
                            prc.Start();
                        }
                        catch { }
                    }
                }
            }
            catch
            {
                //backup, in case on extended message box starts to act up
                MessageBox.Show(stbPromptMessage.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }