예제 #1
0
 public static MessageBoxResult MessageBoxShow(string message, MessageBoxButton button, MessageBoxImage image)
 {
     if (Application.Current.Dispatcher != System.Windows.Threading.Dispatcher.CurrentDispatcher)
     {
         return((MessageBoxResult)Application.Current.Dispatcher.Invoke(new Func <string, MessageBoxButton, MessageBoxImage, MessageBoxResult>(MessageBoxShow), message, button, image));
     }
     else
     {
         ModManagement.SetStandbyBack();
         return(MessageBox.Show(MainWindow, message, GeneralHelper.AssemblyTitle, button, image));
     }
 }
        public void ActivateMod()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            string targetRootPath             = Locations.ArtemisCopyPath;
            List <DictionaryEntry> targetList = new List <DictionaryEntry>();

            FileInfo[] baseFileList = GetFilesFromBaseFiles(BaseFiles.Files);

            if (string.IsNullOrEmpty(InstalledPath))
            {
                SetInstalledPath();
            }
            targetList.AddRange(FileHelper.CopyFiles(new DirectoryInfo(InstalledPath), targetRootPath, baseFileList));
            if (!string.IsNullOrEmpty(FileHelper.CopyFilesProblemMessage))
            {
                ModManagement.SetStandbyBack();
                Locations.MessageBoxShow(FileHelper.CopyFilesProblemMessage, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                FileHelper.CopyFilesProblemMessage = null;
            }
            foreach (FileMap m in BaseFiles.Files)
            {
                if (m.Source.Contains("*") || m.Source.Contains("?"))
                {
                    //more than one file, wildcarded.
                    string sourceFle = m.Source;

                    int i = sourceFle.LastIndexOf('\\');
                    if (i >= 0)
                    {
                        sourceFle = sourceFle.Substring(0, i);
                    }
                    targetList.AddRange(FileHelper.CopyFiles(
                                            new DirectoryInfo(Path.Combine(InstalledPath, sourceFle)),
                                            Path.Combine(targetRootPath, m.Target)));
                    if (!string.IsNullOrEmpty(FileHelper.CopyFilesProblemMessage))
                    {
                        ModManagement.SetStandbyBack();
                        Locations.MessageBoxShow(FileHelper.CopyFilesProblemMessage, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        FileHelper.CopyFilesProblemMessage = null;
                    }
                }
                else
                {
                    string src  = Path.Combine(InstalledPath, m.Source);
                    string targ = Path.Combine(Locations.ArtemisCopyPath, m.Target);
                    FileHelper.Copy(src, targ);
                    targetList.Add(new DictionaryEntry(src, targ));
                }
            }
            ActiveFiles = Application.Current.Dispatcher.Invoke(new Func <FileGroup>(GetNewFileGroup)) as FileGroup;
            if (ActiveFiles != null)
            {
                foreach (DictionaryEntry targ in targetList)
                {
                    FileMap fm = Application.Current.Dispatcher.Invoke(new Func <string, string, bool, FileMap>(GetNewFileMap), targ.Key.ToString(), targ.Value.ToString(), false) as FileMap;
                    if (fm != null)
                    {
                        ActiveFiles.UIThreadAddToCollection <FileMap>(ActiveFiles.Files, fm);
                    }
                    //ActiveFiles.Files.Add(new FileMap(targ.Key.ToString(), targ.Value.ToString()));
                }
            }

            if (this.SubMods != null && this.SubMods.SubMods.Count > 0)
            {
                this.ActivateSubMod(SubMods.SubMods[0].Title);
            }
            ModManagement.SetStandbyBack();
            IsActive = true;
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
        public void ActivateSubMod(string SubModTitle)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            if (string.IsNullOrEmpty(InstalledPath))
            {
                SetInstalledPath();
            }
            //Must first make sure the Mod itself is activated.
            string targetRootPath             = Locations.ArtemisCopyPath;
            List <DictionaryEntry> targetList = new List <DictionaryEntry>();

            if (!string.IsNullOrEmpty(ActiveSubMod) && ActiveSubMod != SubModTitle)
            {
                DeactivateSubMod();
            }
            if (ActiveSubMod != SubModTitle)
            {
                foreach (SubMod sub in SubMods.SubMods)
                {
                    if (sub.Title == SubModTitle)
                    {
                        foreach (FileMap m in sub.Files.Files)
                        {
                            // <FileMap Source="Helm UI Mod\New UI Image Files\*" Target="dat"/>

                            if (m.Source.Contains("*") || m.Source.Contains("?"))
                            {
                                //more than one file, wildcarded.

                                string sourceFle = m.Source;

                                int i = sourceFle.LastIndexOf('\\');
                                sourceFle = sourceFle.Substring(0, i);
                                targetList.AddRange(FileHelper.CopyFiles(
                                                        new DirectoryInfo(Path.Combine(InstalledPath, sourceFle)),
                                                        Path.Combine(targetRootPath, m.Target)));
                                if (!string.IsNullOrEmpty(FileHelper.CopyFilesProblemMessage))
                                {
                                    ModManagement.SetStandbyBack();
                                    Locations.MessageBoxShow(FileHelper.CopyFilesProblemMessage, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    FileHelper.CopyFilesProblemMessage = null;
                                }
                            }
                            else
                            {
                                string src  = Path.Combine(InstalledPath, m.Source);
                                string targ = Path.Combine(Locations.ArtemisCopyPath, m.Target);


                                FileHelper.Copy(src, targ);
                                targetList.Add(new DictionaryEntry(src, targ));
                            }
                        }
                        ActiveSubMod = sub.Title;
                        sub.IsActive = true;
                        break;
                    }
                }
            }

            foreach (DictionaryEntry targ in targetList)
            {
                FileMap fm = Application.Current.Dispatcher.Invoke(new Func <string, string, bool, FileMap>(GetNewFileMap), targ.Key.ToString(), targ.Value.ToString(), true) as FileMap;
                if (fm != null)
                {
                    this.UIThreadAddToCollection <FileMap>(ActiveFiles.Files, fm);
                }
                //ActiveFiles.Files.Add(
                //    new FileMap(targ.Key.ToString(), targ.Value.ToString(), true));
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }