Exemple #1
0
        private void Export()
        {
            try
            {
                if (SelectedMod == null)
                {
                    MessageBox.Show(_("No-Selected-Mod-Error-Message"));
                    return;
                }

                if (string.IsNullOrWhiteSpace(PackageName))
                {
                    MessageBox.Show(_("No-Package-Name-Error-Message"));
                    return;
                }

                var package = new Package
                {
                    Name     = PackageName,
                    Language = SelectedLanguage,
                    ModName  = SelectedMod.Name,
                    Files    = new ObservableCollection <IFile>()
                };

                var dirPath = Utils.EscapePath(Path.Combine(Localizer.Localizer.SourcePackageDirPath, PackageName));

                packageExportService.Export(package,
                                            new ExportConfig
                {
                    ForceOverride   = ForceOverride,
                    MakeBackup      = MakeBackup,
                    WithTranslation = WithTranslation
                });

                IPackage oldPack;
                if (Directory.Exists(dirPath))
                {
                    oldPack = sourcePackageLoadServiceService.Load(dirPath, fileLoadService);
                }
                else
                {
                    Utils.CreateDirectory(dirPath);
                    oldPack = null;
                }

                if (MakeBackup && oldPack != null)
                {
                    var backupDirPath = Utils.EscapePath(Path.Combine(dirPath, "Backups", Utils.DateTimeToFileName(DateTime.Now)));
                    Utils.CreateDirectory(backupDirPath);
                    packageSaveService.Save(oldPack, backupDirPath, fileSaveService);

                    Utils.LogDebug($"[{PackageName}'s backup created.]");
                }

                if (!ForceOverride && oldPack != null)
                {
                    var updateLogger = Localizer.Localizer.Kernel.Get <IUpdateLogService>();
                    updateLogger.Init($"{package.Name}-{Utils.DateTimeToFileName(DateTime.Now)}");

                    packageUpdateService.Update(oldPack, package, updateLogger);

                    packageSaveService.Save(oldPack, dirPath, fileSaveService);
                }
                else
                {
                    packageSaveService.Save(package, dirPath, fileSaveService);
                }

                MessageBox.Show(string.Format(_("Package-Exported-Success-Message"), PackageName));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                Localizer.Localizer.Log.Error(e);
            }
        }
Exemple #2
0
        private void Export(bool withTranslation)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(_modList.SelectedItem?.Text ?? ""))
                {
                    return;
                }

                var name = _modList.SelectedItem.Text;
                var mod  = Localizer.GetWrappedMod(name);

                var enabledPackages = pkgManager.PackageGroups
                                      .FirstOrDefault(g => g.Mod.Name == name)?.Packages
                                      .Where(p => p.Enabled)
                                      .OrderBy(p => p.ModVersion ?? new Version(0, 0, 0, 0))
                                      .ToList();
                var oldPack = enabledPackages?.FirstOrDefault();

                var package = new DataModel.Default.Package
                {
                    Name             = oldPack?.Name ?? name,
                    LocalizedModName = oldPack?.LocalizedModName ?? name,
                    Language         = CultureInfo.GetCultureInfo(Language.ActiveCulture.Name),
                    ModName          = name,
                    Files            = new ObservableCollection <IFile>(),
                    Version          = oldPack?.Version ?? new Version("1.0.0.0"),
                    Author           = oldPack?.Author ?? "",
                    Description      = oldPack?.Description ?? "",
                    Mod        = mod,
                    ModVersion = Version.Parse($"{Math.Max(mod.Version.Major, 0)}.{Math.Max(mod.Version.Minor, 0)}.{Math.Max(mod.Version.Build, 0)}.{Math.Max(mod.Version.Revision, 0)}")
                };

                var dirPath = Utils.EscapePath(Path.Combine(Localizer.SourcePackageDirPath, name));

                packageExportService.Export(package, new DataModel.Default.ExportConfig
                {
                    WithTranslation = withTranslation
                });

                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                if (enabledPackages != null && enabledPackages.Count > 0)
                {
                    oldPack.ModVersion = package.ModVersion;
                    var updateLogger = Localizer.Kernel.Get <IUpdateLogger>();
                    updateLogger.Init($"{package.Name}-{Utils.DateTimeToFileName(DateTime.Now)}");

                    foreach (var item in enabledPackages.Skip(1))
                    {
                        packageUpdateService.Update(oldPack, item, updateLogger);
                    }

                    packageUpdateService.Update(oldPack, package, updateLogger);

                    packageSaveService.Save(oldPack, dirPath, fileSaveService);
                }
                else
                {
                    packageSaveService.Save(package, dirPath, fileSaveService);
                }
            }
            catch (Exception e)
            {
                Localizer.Log.Error(e);
            }
        }