Esempio n. 1
0
        private async Task <PackageVersion> GetPackageVersionAsync(string registry, string packageId, SemVer.Version version)
        {
            // check version is null
            if (version == null)
            {
                // get max version of package
                PackageInfo package = await GetBestMatchPackageVersionsAsync(registry, true, packageId, new SemVer.Range("*"));

                version = package.packageVersion;
            }

            // base url
            string baseUrl = (registry == null || registry == "") ? DefaultNpmRegistry : registry;

            client.BaseUrl = new Uri(baseUrl);

            // get version url
            if (packageId == null || version == null)
            {
                return(null);
            }
            else
            {
                string searchUrl = $"/{packageId}/{version.ToString()}";

                var requestGet = new RestRequest(searchUrl, Method.GET);
                IRestResponse <PackageVersion> result = await client.ExecuteAsync <PackageVersion>(requestGet);

                return(result.Data);
            }
        }
Esempio n. 2
0
        private static void PackageHandler_OnVersionChanged(PackageHandler handler, SemVer.Version version)
        {
            // Perform Android.mk, c_cpp_properties.json, bmbfmod.json edits to version
            var props = propertiesProvider.GetProperties();

            if (props != null)
            {
                props.UpdateVersion(version);
                propertiesProvider.SerializeProperties(props);
            }
            var mod = bmbfmodProvider.GetMod();

            if (mod != null)
            {
                mod.UpdateVersion(version);
                bmbfmodProvider.SerializeMod(mod);
            }
            var conf = configProvider.GetConfig();

            if (conf is null)
            {
                throw new ConfigException("Config is null!");
            }
            if (conf.Info is null)
            {
                throw new ConfigException("Config info is null!");
            }
            if (conf.Info.Id is null)
            {
                throw new ConfigException("Config ID is null!");
            }
            bool overrodeName = conf.Info.AdditionalData.TryGetValue(SupportedPropertiesCommand.OverrideSoName, out var overridenName);
            var  mk           = androidMkProvider.GetFile();

            if (mk != null)
            {
                var module = mk.Modules.LastOrDefault();
                if (module != null)
                {
                    module.AddDefine("VERSION", version.ToString());
                    if (overrodeName)
                    {
                        module.Id = overridenName.GetString().ReplaceFirst("lib", "").ReplaceLast(".so", "");
                    }
                    else
                    {
                        module.EnsureIdIs(conf.Info.Id, version);
                    }
                    androidMkProvider.SerializeFile(mk);
                }
            }
        }
Esempio n. 3
0
        public override JsonElement?GetVersionElement(JsonDocument?contentJSON, Version version)
        {
            if (contentJSON is null)
            {
                return(null);
            }
            JsonElement root = contentJSON.RootElement;

            try
            {
                JsonElement versionsJSON = root.GetProperty("versions");
                foreach (JsonProperty versionProperty in versionsJSON.EnumerateObject())
                {
                    if (versionProperty.Name == version.ToString())
                    {
                        return(versionsJSON.GetProperty(version.ToString()));
                    }
                }
            }
            catch (KeyNotFoundException) { return(null); }
            catch (InvalidOperationException) { return(null); }

            return(null);
        }
Esempio n. 4
0
        public SemanticReleaseVersion GetNextVersion(Release lastRelease, ReleaseType releaseType)
        {
            var lastVersion = lastRelease?.Version;

            if (lastVersion == null)
            {
                return(new SemanticReleaseVersion("1.0.0"));
            }

            var testVersion = new SemanticVersion(lastVersion);

            int nextMajor = testVersion.Major;
            int nextMinor = testVersion.Minor;
            int nextPatch = testVersion.Patch;

            switch (releaseType)
            {
            case ReleaseType.MAJOR:
                nextMajor += 1;
                nextMinor  = 0;
                nextPatch  = 0;
                break;

            case ReleaseType.MINOR:
                nextMinor += 1;
                nextPatch  = 0;
                break;

            case ReleaseType.PATCH:
                nextPatch += 1;
                break;

            default:
                throw new NoOpReleaseException(lastVersion);
            }

            var newVersion = new SemanticVersion($"{nextMajor}.{nextMinor}.{nextPatch}");

            return(new SemanticReleaseVersion(newVersion.ToString()));
        }
 public override JsonElement?GetVersionElement(JsonDocument contentJSON, Version version)
 {
     try
     {
         var versionElement = contentJSON.RootElement.GetProperty("releases").GetProperty(version.ToString());
         return(versionElement);
     }
     catch (KeyNotFoundException)
     {
         return(null);
     }
 }
 public override string ToString()
 {
     return(Value.ToString());
 }
Esempio n. 7
0
 public void EnsureIdIs(string id, SemVer.Version version) => Id = id + "_" + version.ToString().Replace('.', '_');
Esempio n. 8
0
        private static async Task ProcessStep(string projectId, Project.Dependency projectDependency, ProcessContext context)
        {
            var versionRange = new SemVer.Range(projectDependency.Version, true);

            // if already resolved dependency, skip it

            if (context.PackageMap.ContainsKey(projectId))
            {
                if (versionRange.IsSatisfied(context.PackageMap[projectId]) == false)
                {
                    throw new InvalidDataException($"Cannot meet version requirement: {projectId} {projectDependency.Version} (but {context.PackageMap[projectId]})");
                }
                return;
            }

            // download package

            Console.WriteLine("Restore: " + projectId);

            var packageFile    = "";
            var packageVersion = new SemVer.Version(0, 0, 0);
            var nugetTargetFrameworkMoniker = string.Empty;
            var sourceName      = projectId;
            var sourceExtention = ".unitypackage";

            if (string.IsNullOrEmpty(projectDependency.SourceType) == false)
            {
                var source = projectDependency.SourceType.Split(':');
                sourceName = source[0];
                if (source.Length > 1)
                {
                    sourceExtention = source[1];
                    if (sourceExtention.Contains(".") == false)
                    {
                        sourceExtention = sourceExtention.Insert(0, ".");
                    }
                }
            }
            if (projectDependency.Source != "local" && string.IsNullOrEmpty(context.Options.LocalRepositoryDirectory) == false)
            {
                var packages     = LocalPackage.GetPackages(context.Options.LocalRepositoryDirectory, projectId);
                var versionIndex = versionRange.GetSatisfiedVersionIndex(packages.Select(x => x.Item2).ToList());
                if (versionIndex != -1)
                {
                    packageFile    = packages[versionIndex].Item1;
                    packageVersion = packages[versionIndex].Item2;
                }
            }

            if (string.IsNullOrEmpty(packageFile) == false)
            {
            }
            else if (projectDependency.Source == "local")
            {
                var packages     = LocalPackage.GetPackages(context.Options.LocalRepositoryDirectory ?? "", projectId);
                var versionIndex = versionRange.GetSatisfiedVersionIndex(packages.Select(x => x.Item2).ToList());
                if (versionIndex == -1)
                {
                    throw new InvalidOperationException("Cannot find package from local repository: " + projectId);
                }

                packageFile    = packages[versionIndex].Item1;
                packageVersion = packages[versionIndex].Item2;
            }
            else if (projectDependency.Source.StartsWith("github:"))
            {
                var parts = projectDependency.Source.Substring(7).Split('/');
                if (parts.Length != 2)
                {
                    throw new InvalidDataException("Cannot determine github repo information from url: " + projectDependency.Source);
                }

                var r = await GithubPackage.DownloadPackageAsync(parts[0], parts[1], projectId, versionRange, sourceName, sourceExtention, context.Options.Token);

                packageFile    = r.Item1;
                packageVersion = r.Item2;
            }
            else if (projectDependency.Source.StartsWith("nuget:"))
            {
                nugetTargetFrameworkMoniker = projectDependency.Source.Substring(6);

                var r = NugetPackage.DownloadPackage(projectId, projectDependency.Version);
                packageFile    = r.Item1;
                packageVersion = r.Item2;
            }
            else
            {
                throw new InvalidOperationException("Cannot recognize source: " + projectDependency.Source);
            }

            context.PackageMap.Add(projectId, packageVersion);

            if (string.IsNullOrEmpty(nugetTargetFrameworkMoniker))
            {
                var projectFile = Path.Combine(context.OutputDir, $"Assets/UnityPackages/{projectId}.unitypackage.json");

                // apply package
                if (sourceExtention == ".zip")
                {
                    var isCreateProjectFile = SourcePackage.ExtractUnityPackage(packageFile, context.OutputDir,
                                                                                projectId, projectDependency.IncludeExtra, projectDependency.IncludeMerged);
                    if (isCreateProjectFile)
                    {
                        var p = new Project {
                            Id = projectId, Version = packageVersion.ToString()
                        };
                        p.Description = $"Source package";
                        p.Files       = new List <JToken>()
                        {
                            JToken.FromObject($"Assets/UnityPackages/{projectId}")
                        };
                        var jsonSettings = new JsonSerializerSettings
                        {
                            DefaultValueHandling = DefaultValueHandling.Ignore,
                        };
                        File.WriteAllText(projectFile, JsonConvert.SerializeObject(p, Formatting.Indented, jsonSettings));
                        File.WriteAllBytes(projectFile + ".meta", Packer.GenerateMeta(projectFile, projectFile).Item2);
                    }
                }
                else
                {
                    Extracter.ExtractUnityPackage(packageFile, context.OutputDir,
                                                  projectId, projectDependency.IncludeExtra, projectDependency.IncludeMerged);
                }

                // deep into dependencies

                if (File.Exists(projectFile))
                {
                    var project = Project.Load(projectFile);
                    if (project.MergedDependencies != null && projectDependency.IncludeMerged)
                    {
                        foreach (var d in project.MergedDependencies)
                        {
                            if (context.PackageMap.ContainsKey(d.Key) == false)
                            {
                                context.PackageMap[d.Key] = new SemVer.Version(d.Value.Version, true);
                            }
                        }
                    }
                    if (project.Dependencies != null)
                    {
                        foreach (var d in project.Dependencies)
                        {
                            context.DepQueue.Enqueue(d);
                        }
                    }
                }
            }
            else
            {
                // apply package

                NugetPackage.ExtractPackage(projectId, packageVersion.ToString(),
                                            nugetTargetFrameworkMoniker, context.OutputDir);

                // create proxy project file

                var outputDir        = Path.Combine(context.OutputDir, $"Assets/UnityPackages/{projectId}");
                var projectAssetPath = $"Assets/UnityPackages/{projectId}.unitypackage.json";
                var projectFile      = Path.Combine(context.OutputDir, projectAssetPath);
                var p = new Project {
                    Id = projectId, Version = packageVersion.ToString()
                };
                p.Description = $"Nuget package (TFM:{nugetTargetFrameworkMoniker})";
                p.Files       = Directory.GetFiles(outputDir, "*")
                                .Where(f => Path.GetExtension(f).ToLower() != ".meta")
                                .Select(f => JToken.FromObject(f.Substring(outputDir.Length + 1).Replace("\\", "/"))).ToList();
                var jsonSettings = new JsonSerializerSettings
                {
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                };
                File.WriteAllText(projectFile, JsonConvert.SerializeObject(p, Formatting.Indented, jsonSettings));

                File.WriteAllBytes(projectFile + ".meta",
                                   Packer.GenerateMeta(projectFile, projectAssetPath).Item2);
            }
        }
Esempio n. 9
0
 /// <inheritdoc />
 public override void WriteJson(JsonWriter writer, Version value, JsonSerializer serializer)
 {
     writer.WriteValue(value.ToString());
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            foreach (var arg in args)
            {
                if (String.IsNullOrWhiteSpace(arg))
                {
                    continue;
                }

                if (arg.Equals("-silent"))
                {
                    isSilent = true;
                }
                else if (arg.Equals("-silent_minor"))
                {
                    isSilentMinor = true;
                }
                else if (arg.Equals("-update_major"))
                {
                    installType = UpdateType.Major;
                }
                else if (arg.Equals("-update_minor"))
                {
                    installType = UpdateType.Minor;
                }

                passedArgs += arg + " ";
            }

            passedArgs.TrimEnd(' ');

            exePath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            //Check privilege
            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
            string _maj = "";

            string auroraPath;

            if (File.Exists(auroraPath = Path.Combine(exePath, "Aurora.exe")))
            {
                _maj = FileVersionInfo.GetVersionInfo(auroraPath).FileVersion;
            }

            if (String.IsNullOrWhiteSpace(_maj))
            {
                if (!isSilent)
                {
                    MessageBox.Show(
                        "Application launched incorrectly, no version was specified.\r\nPlease use Aurora if you want to check for updates.\r\nOptions -> \"Updates\" \"Check for Updates\"",
                        "Aurora Updater",
                        MessageBoxButtons.OK);
                }
                return;
            }
            versionMajor = new Version(_maj, true);

            //Initialize UpdateManager
            StaticStorage.Manager = new UpdateManager(versionMajor);

            //Check if update retrieval was successful.
            if (StaticStorage.Manager.updateState == UpdateStatus.Error)
            {
                return;
            }

            if (installType != UpdateType.Undefined)
            {
                if (isElevated)
                {
                    updateForm = new MainForm(installType);
                    updateForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show(
                        "Updater was not granted Admin rights.",
                        "Aurora Updater - Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
            else
            {
                Version latestV = new Version(StaticStorage.Manager.LatestRelease.TagName.TrimStart('v'), true);

                if (latestV > versionMajor)
                {
                    UpdateInfoForm userResult = new UpdateInfoForm()
                    {
                        changelog         = StaticStorage.Manager.LatestRelease.Body,
                        updateDescription = StaticStorage.Manager.LatestRelease.Name,
                        updateVersion     = latestV.ToString(),
                        currentVersion    = versionMajor.ToString(),
                        updateSize        = StaticStorage.Manager.LatestRelease.Assets.First(s => s.Name.StartsWith("release") || s.Name.StartsWith("Aurora-v")).Size,
                        preRelease        = StaticStorage.Manager.LatestRelease.Prerelease
                    };

                    userResult.ShowDialog();

                    if (userResult.DialogResult == DialogResult.OK)
                    {
                        if (isElevated)
                        {
                            updateForm = new MainForm(UpdateType.Major);
                            updateForm.ShowDialog();
                        }
                        else
                        {
                            //Request user to grant admin rights
                            try
                            {
                                ProcessStartInfo updaterProc = new ProcessStartInfo();
                                updaterProc.FileName  = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                                updaterProc.Arguments = passedArgs + " -update_major";
                                updaterProc.Verb      = "runas";
                                Process.Start(updaterProc);

                                return; //Exit, no further action required
                            }
                            catch (Exception exc)
                            {
                                MessageBox.Show(
                                    $"Could not start Aurora Updater. Error:\r\n{exc}",
                                    "Aurora Updater - Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                else
                {
                    if (!isSilent)
                    {
                        MessageBox.Show(
                            "You have latest version of Aurora installed.",
                            "Aurora Updater",
                            MessageBoxButtons.OK);
                    }
                }

                /*string _min = "";
                 *
                 * if (File.Exists(Path.Combine(exePath, "ver_minor.txt")))
                 *  _min = File.ReadAllText(Path.Combine(exePath, "ver_minor.txt"));
                 *
                 * if (!String.IsNullOrWhiteSpace(_min))
                 * {
                 *  versionMinor = new UpdateVersion(_min);
                 *
                 *  if (!(StaticStorage.Manager.response.Minor.Version <= versionMinor))
                 *  {
                 *      if (isSilentMinor)
                 *          StaticStorage.Manager.RetrieveUpdate(UpdateType.Minor);
                 *      else
                 *      {
                 *          UpdateInfoForm userResult = new UpdateInfoForm()
                 *          {
                 *              changelog = StaticStorage.Manager.response.Minor.Changelog,
                 *              updateDescription = StaticStorage.Manager.response.Minor.Description,
                 *              updateVersion = StaticStorage.Manager.response.Minor.Version.ToString(),
                 *              currentVersion = versionMinor.ToString(),
                 *              updateSize = StaticStorage.Manager.response.Minor.FileSize,
                 *              preRelease = StaticStorage.Manager.response.Minor.PreRelease
                 *          };
                 *
                 *          userResult.ShowDialog();
                 *
                 *          if (userResult.DialogResult == DialogResult.Yes)
                 *          {
                 *              if (isElevated)
                 *              {
                 *                  updateForm = new MainForm(UpdateType.Minor);
                 *                  updateForm.ShowDialog();
                 *              }
                 *              else
                 *              {
                 *                  //Request user to grant admin rights
                 *                  try
                 *                  {
                 *                      ProcessStartInfo updaterProc = new ProcessStartInfo();
                 *                      updaterProc.FileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                 *                      updaterProc.Arguments = passedArgs + " -update_minor";
                 *                      updaterProc.Verb = "runas";
                 *                      Process.Start(updaterProc);
                 *
                 *                      return; //Exit, no further action required
                 *                  }
                 *                  catch (Exception exc)
                 *                  {
                 *                      MessageBox.Show(
                 *                          $"Could not start Aurora Updater. Error:\r\n{exc}",
                 *                          "Aurora Updater - Error",
                 *                          MessageBoxButtons.OK,
                 *                          MessageBoxIcon.Error);
                 *                  }
                 *              }
                 *          }
                 *      }
                 *
                 *  }
                 *  else
                 *  {
                 *      if (!isSilent && !isSilentMinor)
                 *          MessageBox.Show(
                 *              "You have latest Minor version of Aurora installed.",
                 *              "Aurora Updater",
                 *              MessageBoxButtons.OK);
                 *  }
                 * }
                 * else
                 * {
                 *  if (!isSilent)
                 *      MessageBox.Show(
                 *          "Application launched incorrectly, no version was specified.\r\nPlease use Aurora if you want to check for updates.\r\nOptions -> \"Updates\" \"Check for Updates\"",
                 *          "Aurora Updater",
                 *          MessageBoxButtons.OK);
                 * }*/
            }
        }