Пример #1
0
        /// <summary>
        /// Gets Moddata from paks if not already in ModList
        /// </summary>
        #region GetModData
        /// <summary>
        /// Gets Moddata from paks if not already in ModList
        /// </summary>
        public async void GetModDataAsync()
        {
            string modDir = Path.Combine(Path.GetDirectoryName(Dos2.ModManager.Properties.Settings.Default.Mods), @"Mods");

            // checks
            #region checks
            if (!Directory.Exists(Dos2.ModManager.Properties.Settings.Default.WorkingDir) ||
                !Directory.Exists(modDir))
            {
                MessageBoxResult result = MessageBox.Show(
                    "No mod directory found. Please check your paths.",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                ParentViewModel.Logger.Status = "Finished With Errors.";
                return;
            }
            if (!Directory.GetFiles(modDir).ToList().Any())
            {
                return;
            }
            #endregion

            try
            {
                List <string> modFiles = Directory.GetFiles(modDir).ToList();

                //Logging Start
                ParentViewModel.Logger.ProgressValue   = 0;
                ParentViewModel.Logger.IsIndeterminate = false;
                ParentViewModel.Logger.LogString("Fetching Mod Data...");
                ParentViewModel.Logger.Status = "Fetching mod data...";

                for (int i = 0; i < modFiles.Count; i++)
                {
                    string modPath = modFiles[i];

                    //get UUID
                    string uuid = Path.GetFileNameWithoutExtension(modPath).Split('_').Last();
                    string meta = "";

                    //check if mod is already in ModList
                    // FIXME check for updates
                    if (!ModsList.Where(x => x.UUID.Equals(uuid)).Any())
                    {
                        meta = await Task.Run(() => ParentViewModel.pt.ExtractModMeta(modPath));

                        if (String.IsNullOrEmpty(meta))
                        {
                            continue;
                        }

                        //interpret meta.lsx
                        Dos2Mod mod = InterpretModMeta(meta);
                        mod.PakPath = modPath;

                        //add to modslist
                        ModsList.Add(mod);
                    }
                    else
                    {
                        //is updated
                        Dos2Mod oldmod = ModsList.FirstOrDefault(x => x.UUID.Equals(uuid));
                        if (oldmod.IsUpdated)
                        {
                            //extract meta.lsx and interpret

                            //replace existing mod
                            throw new NotImplementedException();
                        }
                        else
                        {
                            //do nothing.
                        }
                    }

                    //Logging Progress
                    int prg = Convert.ToInt32(100 / (modFiles.Count - 1) * i);
                    ParentViewModel.Logger.ProgressValue = prg;
                }

                //Logging End
                ParentViewModel.Logger.IsIndeterminate = false;
                ParentViewModel.Logger.Status          = "Finished.";
                ParentViewModel.Logger.LogString("Finished fetching mod data...");
                ParentViewModel.Logger.NotifyStatusChanged();

                // populate files list for mods
                GetModFilesAsync();
                ApplyModSettings(ParentViewModel.ActiveProfile);
            }
            catch (Exception e)
            {
                MessageBoxResult result = MessageBox.Show(
                    "Something went wrong when trying to load mod data. Please check your paths.",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                ParentViewModel.Logger.Status = "Finished With Errors.";
                ParentViewModel.Logger.LogString("Something went wrong when trying to load mod data. Please check your paths.");
                ParentViewModel.Logger.LogString(e.ToString());
                return;
            }
        }