Пример #1
0
        public static SwiftyRepo MapToSwifty(RepoProfile profile)
        {
            var swiftyRepo = new SwiftyRepo
            {
                RepoName         = profile.Repository.Name,
                BasePath         = profile.Repository.BasePath,
                RepoImagePath    = Constants.RepoImageFileName,
                IconImagePath    = Constants.RepoIconFileName,
                ClientParameters = profile.Repository.ClientParams,
                Servers          = new List <SwiftyServer>
                {
                    new SwiftyServer
                    {
                        Name      = profile.Repository.ServerInfo.Name,
                        Address   = profile.Repository.ServerInfo.Address,
                        Port      = profile.Repository.ServerInfo.Port,
                        Password  = profile.Repository.ServerInfo.Password,
                        BattleEye = profile.Repository.ServerInfo.BattleEye
                    }
                },
                RequiredMods = profile.Repository.Mods.Select(m => new SwiftyMod {
                    ModName = m, Enabled = true
                }).ToList(),
                OptionalMods = profile.Repository.OptionalMods.Select(m => new SwiftyMod {
                    ModName = m, Enabled = true
                }).ToList(),
            };

            return(swiftyRepo);
        }
Пример #2
0
 public static RepoProfileViewModel GetViewModelFromData(this RepoProfile repoProfile)
 {
     return(new RepoProfileViewModel
     {
         Name = repoProfile.Name,
         Repository = repoProfile.Repository.GetViewModelFromData()
     });
 }
Пример #3
0
        public RepoProfile DuplicateProfile(RepoProfile profile)
        {
            // using JSON to deep copy the object
            var serialized   = JsonConvert.SerializeObject(profile);
            var deserialized = JsonConvert.DeserializeObject <RepoProfile>(serialized);

            deserialized.Name = "Copy of " + deserialized.Name;

            return(deserialized);
        }
Пример #4
0
 public RepoProfile RenameProfile(RepoProfile profile, string newProfileName)
 {
     profile.Name = newProfileName;
     return(profile);
 }
Пример #5
0
 public void AddProfile(Settings settings, RepoProfile newProfile)
 {
     settings.RepoProfiles.Add(newProfile);
     settings.RepoProfiles = settings.RepoProfiles.OrderBy(p => p.Name).ToList();
 }
Пример #6
0
        public void CreateRepository(RepoProfile repoProfile, string modFolderPath, string swiftyCliPath, string repoSourceFolderPath)
        {
            // create repo source folder
            var diSourceFolder = new DirectoryInfo(Path.Combine(repoSourceFolderPath, IoHelper.SanitizeFolderName(repoProfile.Name)));

            if (!diSourceFolder.Exists)
            {
                diSourceFolder.Create();
            }

            // clean source directory from files and folders
            foreach (var file in diSourceFolder.EnumerateFiles())
            {
                file.Delete();
            }

            foreach (var dir in diSourceFolder.EnumerateDirectories())
            {
                dir.Delete(true);
            }

            // set the source folder
            repoProfile.Repository.BasePath = diSourceFolder.FullName;

            // clean target directory from files and folders
            var diTargetFolder = new DirectoryInfo(repoProfile.Repository.TargetPath);

            if (!diTargetFolder.Exists)
            {
                diTargetFolder.Create();
            }

            foreach (var file in diTargetFolder.EnumerateFiles())
            {
                file.Delete();
            }

            foreach (var dir in diTargetFolder.EnumerateDirectories())
            {
                dir.Delete(true);
            }


            // copy repo.png
            var fiRepoImage = new FileInfo(repoProfile.Repository.ImagePath);

            if (!fiRepoImage.Exists)
            {
                throw new InvalidOperationException($"repo.png at '{repoProfile.Repository.ImagePath}' does not exist.");
            }

            fiRepoImage.CopyTo(Path.Combine(diSourceFolder.FullName, Constants.RepoImageFileName), true);


            // copy icon.png
            var fiRepoIcon = new FileInfo(repoProfile.Repository.IconPath);

            if (!fiRepoIcon.Exists)
            {
                throw new InvalidOperationException($"icon.png at '{repoProfile.Repository.IconPath}' does not exist.");
            }

            fiRepoIcon.CopyTo(Path.Combine(diSourceFolder.FullName, Constants.RepoIconFileName), true);


            // create repo.json
            var swiftyRepo = SwiftyJsonHelper.MapToSwifty(repoProfile);
            var fiRepoJson = new FileInfo(Path.Combine(diSourceFolder.FullName, Constants.RepoConfigFileName));

            var serializer = new JsonSerializer
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            using (var sr = fiRepoJson.CreateText())
            {
                serializer.Serialize(sr, swiftyRepo);
            }

            // Merge both mod lists (required and optional)
            var allMods = repoProfile.Repository.Mods.Concat(repoProfile.Repository.OptionalMods).ToList();

            // create Junctions for required mods in source folder
            foreach (var mod in allMods)
            {
                JunctionPoint.Create(Path.Combine(modFolderPath, mod), Path.Combine(diSourceFolder.FullName, mod), true);
            }

            // delete old mod.srf files
            foreach (var dir in diSourceFolder.EnumerateDirectories())
            {
                var fiModSrf = new FileInfo(Path.Combine(dir.FullName, Constants.ModDescriptionFileName));
                if (fiModSrf.Exists)
                {
                    fiModSrf.Delete();
                }
            }


            // execute swifty-cli
            ProcessHelper.ExecuteProcess($"\"{swiftyCliPath}\" create \"{fiRepoJson.FullName}\" \"{repoProfile.Repository.TargetPath}\" --nocopy");


            foreach (var dir in diTargetFolder.EnumerateDirectories())
            {
                var modName = allMods.Single(m => m.Equals(dir.Name, StringComparison.OrdinalIgnoreCase));

                // in the target folder rename created mod folders to temp
                dir.MoveTo($"{dir.FullName}_temp");


                // create mod junction
                var newModJunctionPath = Path.Combine(diTargetFolder.FullName, modName);
                JunctionPoint.Create(Path.Combine(modFolderPath, modName), newModJunctionPath, true);

                // move srf file to junction folder
                var fiModSrf      = new FileInfo(Path.Combine(dir.FullName, Constants.ModDescriptionFileName));
                var newModSrfPath = Path.Combine(newModJunctionPath, Constants.ModDescriptionFileName);
                if (File.Exists(newModSrfPath))
                {
                    File.Delete(newModSrfPath);
                }
                fiModSrf.MoveTo(newModSrfPath);

                // delete temp folder
                dir.Delete(true);
            }
        }
Пример #7
0
 private void CreateRepository(RepoProfile profile)
 {
     _repoManager.CreateRepository(profile, _settings.ModsFolderPath, _settings.SwiftyCliPath, _settings.RepoSourceFolderPath);
 }
Пример #8
0
        public static RepoValidation IsRepoValid(RepoProfile profile)
        {
            var result = RepoValidation.Valid;

            if (string.IsNullOrEmpty(profile.Repository.Name))
            {
                if (result.HasFlag(RepoValidation.Valid))
                {
                    result = RepoValidation.RepoNameMissing;
                }
                else
                {
                    result = result | RepoValidation.RepoNameMissing;
                }
            }

            if (string.IsNullOrEmpty(profile.Repository.TargetPath))
            {
                if (result.HasFlag(RepoValidation.Valid))
                {
                    result = RepoValidation.TargetPathMissing;
                }
                else
                {
                    result = result | RepoValidation.TargetPathMissing;
                }
            }

            if (string.IsNullOrEmpty(profile.Repository.ImagePath))
            {
                if (result.HasFlag(RepoValidation.Valid))
                {
                    result = RepoValidation.ImagePathMissing;
                }
                else
                {
                    result = result | RepoValidation.ImagePathMissing;
                }
            }

            if (string.IsNullOrEmpty(profile.Repository.IconPath))
            {
                if (result.HasFlag(RepoValidation.Valid))
                {
                    result = RepoValidation.IconPathMissing;
                }
                else
                {
                    result = result | RepoValidation.IconPathMissing;
                }
            }

            if (!profile.Repository.Mods.Any())
            {
                if (result.HasFlag(RepoValidation.Valid))
                {
                    result = RepoValidation.ModsMissing;
                }
                else
                {
                    result = result | RepoValidation.ModsMissing;
                }
            }

            return(result);
        }
Пример #9
0
 public ProfileController(ISms sms)
 {
     _sms         = sms;
     _repoProfile = new RepoProfile();
     db           = new ApplicationDbContext();
 }