Ejemplo n.º 1
0
        public void AddPackage(string name, string description, string version, string archive, bool force, Func <List <string>, int> multiRoot)
        {
            var p = new Package
            {
                Name        = name,
                Description = description,
                Version     = version
            };

            var package = driveRepository.GetPackages().SingleOrDefault(pa => pa.Id == p.Id);

            if (package != null)
            {
                if (package.SemanticVersion >= p.SemanticVersion && !force)
                {
                    throw new ArgumentException($"Package already exists with Version '{package.SemanticVersion.ToNormalizedString()}'!");
                }

                RemovePackage(name);
            }

            var allowedArchives = new List <string> {
                ".zip", ".rar"
            };
            var ext = Path.GetExtension(archive);

            if (!allowedArchives.Contains(ext))
            {
                throw new ArgumentException($"Only '{string.Join(",", allowedArchives)}' Archives implemented!");
            }


            driveRepository.AddPackage(p, PackageBuilder.Create(archive, WoTHelper.GetWoTVersion(wotGameDirectory), multiRoot));
        }
Ejemplo n.º 2
0
        public IEnumerable <string> InstallPackageStream(Stream packageStream, string wotHome)
        {
            var wotVersion = WoTHelper.GetWoTVersion(wotHome);
            //WotHome\mods
            var modsPath = Path.Combine(wotHome, Constants.ModsFolder);

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

            //WotHome\mods\0.9.xxxx
            var modsVersionPath = Path.Combine(modsPath, wotVersion);

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

            //WotHome\res_mods
            var resmodsPath = Path.Combine(wotHome, Constants.ResModsFolder);

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

            //WotHome\res_mods\0.9.xxxx
            var resmodsVersionPath = Path.Combine(resmodsPath, wotVersion);

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


            packageStream.Seek(0, SeekOrigin.Begin);
            List <string> files = new List <string>();

            using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Read, true))
            {
                foreach (ZipArchiveEntry entry in archive.Entries.Where(en => !string.IsNullOrEmpty(en.Name)))
                {
                    var entryFullName = Path.Combine(wotHome, entry.FullName);
                    entryFullName = entryFullName.Replace(Constants.VersionPlaceHolder, wotVersion);

                    if (!Directory.Exists(Path.GetDirectoryName(entryFullName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(entryFullName));
                    }

                    entry.ExtractToFile(entryFullName, true);
                    files.Add(entryFullName);
                }
            }

            return(files);
        }
Ejemplo n.º 3
0
        public void UninstallPackageStream(Stream packageStream, string wotHome)
        {
            var wotVersion = WoTHelper.GetWoTVersion(wotHome);

            packageStream.Seek(0, SeekOrigin.Begin);
            using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Read, true))
            {
                foreach (ZipArchiveEntry entry in archive.Entries.OrderBy(en => string.IsNullOrEmpty(en.Name)))
                {
                    var entryFullName = Path.Combine(wotHome, entry.FullName);
                    entryFullName = entryFullName.Replace("_version_", wotVersion);

                    if (File.Exists(entryFullName))
                    {
                        File.Delete(entryFullName);
                    }

                    rekDeleteDirectory(Path.GetDirectoryName(entryFullName));
                }
            }
        }
Ejemplo n.º 4
0
 public string GetWotVersion()
 {
     return(WoTHelper.GetWoTVersion(database.WoTHome));
 }
Ejemplo n.º 5
0
 public void Init(string wotGameDirectory, bool force)
 {
     database.Init(wotGameDirectory, WoTHelper.GetWoTVersion(wotGameDirectory), force);
 }
Ejemplo n.º 6
0
 public static string GetWotVersion(string wotHome)
 {
     return(WoTHelper.GetWoTVersion(wotHome));
 }