/// <summary>
 /// This asks the user to confirm the overwriting of the specified item.
 /// </summary>
 /// <param name="p_strItemMessage">The message describing the item being overwritten..</param>
 /// <param name="p_booAllowPerGroupChoice">Whether to allow the user to make the decision to amke the selection for all items in the current item's group.</param>
 /// <param name="p_booAllowPerModChoice">Whether to allow the user to make the decision to make the selection for all items in the current Mod.</param>
 /// <returns>The user's choice.</returns>
 private OverwriteResult ConfirmItemOverwrite(string p_strItemMessage, bool p_booAllowPerGroupChoice, bool p_booAllowPerModChoice)
 {
     if (InvokeRequired)
     {
         return((OverwriteResult)Invoke((ConfirmItemOverwriteDelegate)ConfirmItemOverwrite, p_strItemMessage, p_booAllowPerGroupChoice, p_booAllowPerModChoice));
     }
     return(OverwriteForm.ShowDialog(this, p_strItemMessage, p_booAllowPerGroupChoice, p_booAllowPerModChoice));
 }
        private bool?TestOverwriteFileLink(IMod mod, string baseFilePath, out int priority, out List <IVirtualModLink> modLinks)
        {
            var fileLinkPriority = VirtualModActivator.CheckFileLink(baseFilePath, out var modCheck, out modLinks);

            priority = fileLinkPriority;
            var loweredPath = baseFilePath.ToLowerInvariant();

            if (fileLinkPriority >= 0)
            {
                if (_overwriteFolders.Contains(Path.GetDirectoryName(loweredPath)))
                {
                    return(true);
                }

                if (_doNotOverwriteFolders.Contains(Path.GetDirectoryName(loweredPath)))
                {
                    return(false);
                }

                if (_overwriteAll)
                {
                    return(true);
                }

                if (_doNotOverwriteAll)
                {
                    return(false);
                }
            }

            if (modCheck == mod)
            {
                return(null);
            }

            if (modCheck == VirtualModActivator.DummyMod)
            {
                VirtualModActivator.OverwriteLooseFile(baseFilePath, Path.GetFileName(mod.Filename));
                return(true);
            }

            if (modCheck != null)
            {
                var modFile   = modCheck.Filename;
                var modFileId = modCheck.Id;

                if (!string.IsNullOrEmpty(modFileId))
                {
                    if (_overwriteMods.Contains(modFileId))
                    {
                        return(true);
                    }

                    if (_doNotOverwriteMods.Contains(modFileId))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (_overwriteMods.Contains(modFile))
                    {
                        return(true);
                    }

                    if (_doNotOverwriteMods.Contains(modFile))
                    {
                        return(false);
                    }
                }

                string strMessage = $"Data file '{baseFilePath}' has already been installed by '{modCheck.ModName}'";
                strMessage += Environment.NewLine + "Activate this mod's file instead?";

                switch (OverwriteForm.ShowDialog(strMessage, true, true))
                {
                case OverwriteResult.Yes:
                    return(true);

                case OverwriteResult.No:
                    return(false);

                case OverwriteResult.NoToAll:
                    _doNotOverwriteAll = true;
                    return(false);

                case OverwriteResult.YesToAll:
                    _overwriteAll = true;
                    return(true);

                case OverwriteResult.NoToGroup:
                    Queue <string> folders = new Queue <string>();
                    folders.Enqueue(Path.GetDirectoryName(loweredPath));

                    while (folders.Count > 0)
                    {
                        loweredPath = folders.Dequeue();

                        if (!_overwriteFolders.Contains(loweredPath))
                        {
                            _doNotOverwriteFolders.Add(loweredPath);

                            if (Directory.Exists(loweredPath))
                            {
                                foreach (var s in Directory.GetDirectories(loweredPath))
                                {
                                    folders.Enqueue(s.ToLowerInvariant());
                                }
                            }
                        }
                    }

                    return(false);

                case OverwriteResult.YesToGroup:
                    folders = new Queue <string>();
                    folders.Enqueue(Path.GetDirectoryName(loweredPath));

                    while (folders.Count > 0)
                    {
                        loweredPath = folders.Dequeue();

                        if (!_doNotOverwriteFolders.Contains(loweredPath))
                        {
                            _overwriteFolders.Add(loweredPath);
                            if (Directory.Exists(loweredPath))
                            {
                                foreach (var s in Directory.GetDirectories(loweredPath))
                                {
                                    folders.Enqueue(s.ToLowerInvariant());
                                }
                            }
                        }
                    }
                    return(true);

                case OverwriteResult.NoToMod:
                    modFile   = modCheck.Filename;
                    modFileId = modCheck.Id;

                    if (!string.IsNullOrEmpty(modFileId))
                    {
                        if (!_overwriteMods.Contains(modFileId))
                        {
                            _doNotOverwriteMods.Add(modFileId);
                        }
                    }
                    else
                    {
                        if (!_overwriteMods.Contains(modFile))
                        {
                            _doNotOverwriteMods.Add(modFile);
                        }
                    }
                    return(false);

                case OverwriteResult.YesToMod:
                    modFile   = modCheck.Filename;
                    modFileId = modCheck.Id;

                    if (!string.IsNullOrEmpty(modFileId))
                    {
                        if (!_doNotOverwriteMods.Contains(modFileId))
                        {
                            _overwriteMods.Add(modFileId);
                        }
                    }
                    else
                    {
                        if (!_doNotOverwriteMods.Contains(modFile))
                        {
                            _overwriteMods.Add(modFile);
                        }
                    }
                    return(true);

                default:
                    throw new Exception("Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum");
                }
            }

            return(true);
        }
        private bool?TestOverwriteFileLink(IMod p_modMod, string p_strBaseFilePath, out Int32 p_intPriority, out List <IVirtualModLink> p_lstFileLinks)
        {
            IMod  modCheck;
            Int32 intPriority = VirtualModActivator.CheckFileLink(p_strBaseFilePath, out modCheck, out p_lstFileLinks);

            p_intPriority = intPriority;
            string strLoweredPath = p_strBaseFilePath.ToLowerInvariant();

            if (intPriority >= 0)
            {
                if (m_lstOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath)))
                {
                    return(true);
                }
                if (m_lstDontOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath)))
                {
                    return(false);
                }
                if (m_booOverwriteAll)
                {
                    return(true);
                }
                if (m_booDontOverwriteAll)
                {
                    return(false);
                }
            }

            if (modCheck == p_modMod)
            {
                return(null);
            }

            string strModFile   = String.Empty;
            string strModFileID = String.Empty;
            string strMessage   = null;

            if (modCheck == VirtualModActivator.DummyMod)
            {
                VirtualModActivator.OverwriteLooseFile(p_strBaseFilePath, Path.GetFileName(p_modMod.Filename));
                return(true);
            }
            else if (modCheck != null)
            {
                strModFile   = modCheck.Filename;
                strModFileID = modCheck.Id;
                if (!String.IsNullOrEmpty(strModFileID))
                {
                    if (m_lstOverwriteMods.Contains(strModFileID))
                    {
                        return(true);
                    }
                    if (m_lstDontOverwriteMods.Contains(strModFileID))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (m_lstOverwriteMods.Contains(strModFile))
                    {
                        return(true);
                    }
                    if (m_lstDontOverwriteMods.Contains(strModFile))
                    {
                        return(false);
                    }
                }
                strMessage  = String.Format("Data file '{{0}}' has already been installed by '{1}'", p_strBaseFilePath, modCheck.ModName);
                strMessage += Environment.NewLine + "Activate this mod's file instead?";

                switch (OverwriteForm.ShowDialog(String.Format(strMessage, p_strBaseFilePath), true, (modCheck != null)))
                {
                case OverwriteResult.Yes:
                    return(true);

                case OverwriteResult.No:
                    return(false);

                case OverwriteResult.NoToAll:
                    m_booDontOverwriteAll = true;
                    return(false);

                case OverwriteResult.YesToAll:
                    m_booOverwriteAll = true;
                    return(true);

                case OverwriteResult.NoToGroup:
                    Queue <string> folders = new Queue <string>();
                    folders.Enqueue(Path.GetDirectoryName(strLoweredPath));
                    while (folders.Count > 0)
                    {
                        strLoweredPath = folders.Dequeue();
                        if (!m_lstOverwriteFolders.Contains(strLoweredPath))
                        {
                            m_lstDontOverwriteFolders.Add(strLoweredPath);
                            if (Directory.Exists(strLoweredPath))
                            {
                                foreach (string s in Directory.GetDirectories(strLoweredPath))
                                {
                                    folders.Enqueue(s.ToLowerInvariant());
                                }
                            }
                        }
                    }
                    return(false);

                case OverwriteResult.YesToGroup:
                    folders = new Queue <string>();
                    folders.Enqueue(Path.GetDirectoryName(strLoweredPath));
                    while (folders.Count > 0)
                    {
                        strLoweredPath = folders.Dequeue();
                        if (!m_lstDontOverwriteFolders.Contains(strLoweredPath))
                        {
                            m_lstOverwriteFolders.Add(strLoweredPath);
                            if (Directory.Exists(strLoweredPath))
                            {
                                foreach (string s in Directory.GetDirectories(strLoweredPath))
                                {
                                    folders.Enqueue(s.ToLowerInvariant());
                                }
                            }
                        }
                    }
                    return(true);

                case OverwriteResult.NoToMod:
                    strModFile   = modCheck.Filename;
                    strModFileID = modCheck.Id;
                    if (!String.IsNullOrEmpty(strModFileID))
                    {
                        if (!m_lstOverwriteMods.Contains(strModFileID))
                        {
                            m_lstDontOverwriteMods.Add(strModFileID);
                        }
                    }
                    else
                    {
                        if (!m_lstOverwriteMods.Contains(strModFile))
                        {
                            m_lstDontOverwriteMods.Add(strModFile);
                        }
                    }
                    return(false);

                case OverwriteResult.YesToMod:
                    strModFile   = modCheck.Filename;
                    strModFileID = modCheck.Id;
                    if (!String.IsNullOrEmpty(strModFileID))
                    {
                        if (!m_lstDontOverwriteMods.Contains(strModFileID))
                        {
                            m_lstOverwriteMods.Add(strModFileID);
                        }
                    }
                    else
                    {
                        if (!m_lstDontOverwriteMods.Contains(strModFile))
                        {
                            m_lstOverwriteMods.Add(strModFile);
                        }
                    }
                    return(true);

                default:
                    throw new Exception("Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum");
                }
            }
            else
            {
                return(true);
            }
        }