static void CreateDefaultManifests(BuilderOptions options) { Directory.CreateDirectory(options.OutputPath); var Manifests = new List <Manifest>(); UpdateChannel[] channels = Enum.GetValues(typeof(UpdateChannel)) as UpdateChannel[]; foreach (UpdateChannel ch in channels) { string BuildListFilename = ch.ToString() + "BuildList.txt"; Manifests.Add(new Manifest() { Channel = ch.ToString(), LatestVersion = "", LastUpdate = DateTime.Now, BuildListURL = options.URL + BuildListFilename, }); File.WriteAllText(BuildListFilename, "[\n]"); } File.WriteAllText(Path.GetFileName(options.Manifest), JsonConvert.SerializeObject(Manifests)); }
static void Main(string[] args) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); settings.Formatting = Formatting.Indented; settings.DateFormatHandling = DateFormatHandling.IsoDateFormat; settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); return(settings); }; var options = new CommandOptions(); string verbName = ""; object verbOptions = null; if (!CommandLine.Parser.Default.ParseArguments(args, options, (verb, obj) => { verbName = verb; verbOptions = obj; })) { Console.WriteLine("Failed to parse console args"); HelpText text = new HelpText(); if (options.BuilderOptions != null) { Console.WriteLine(text.RenderParsingErrorsText(options.BuilderOptions, 1)); } if (options.UpdaterOptions != null) { Console.WriteLine(text.RenderParsingErrorsText(options.UpdaterOptions, 1)); } Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } if (verbName == "createBuild") { BuilderOptions op = verbOptions as BuilderOptions; CreateBuild(op); } else if (verbName == "update") { UpdaterOptions op = verbOptions as UpdaterOptions; DownloadLatestVersion(op); } }
static void CreateDefaultManifests(BuilderOptions options) { Directory.CreateDirectory(options.OutputPath); var Manifests = new List<Manifest>(); UpdateChannel[] channels = Enum.GetValues(typeof(UpdateChannel)) as UpdateChannel[]; foreach (UpdateChannel ch in channels) { string BuildListFilename = ch.ToString() + "BuildList.txt"; Manifests.Add(new Manifest() { Channel = ch.ToString(), LatestVersion = "", LastUpdate = DateTime.Now, BuildListURL = options.URL + BuildListFilename, }); File.WriteAllText(BuildListFilename, "[\n]"); } File.WriteAllText(Path.GetFileName(options.Manifest), JsonConvert.SerializeObject(Manifests)); }
static void CreateBuild(BuilderOptions options) { Console.WriteLine("Creating Build for " + options.UpdateChannel.ToString() + " version " + options.Version); List<Manifest> Manifests; //Get the Manifests if the file exists. If it doesn't, create it if (!File.Exists(options.Manifest)) { Console.WriteLine("Manifest file does not exist, creating Manifests"); CreateDefaultManifests(options); } Manifests = JsonConvert.DeserializeObject<List<Manifest>>(File.ReadAllText(options.Manifest)); //Get the update channel we are building for Manifest man = Manifests.FirstOrDefault(x => x.Channel == options.UpdateChannel.ToString()); if (man == null) { Console.WriteLine("Error: Cannot find the manifest for " + options.Manifest + "! Aborting."); Environment.Exit(0); } //Get the list of builds string buildListFilename = options.UpdateChannel.ToString() + "BuildList.txt"; List<Build> builds = JsonConvert.DeserializeObject<List<Build>>(File.ReadAllText(buildListFilename)); Console.WriteLine("Creating build information"); //Create the build Build b = new Build() { FileName = Path.GetFileName(options.BuildFile), DownloadURL = options.URL + options.UpdateChannel.ToString() + "/", Notes = options.UpdateNotes, DetailURL = options.DetailedNotesURL, Version = options.Version, Date = DateTime.Now, }; Console.WriteLine("Writing Build"); //Copy the file to the output directory string outputDir = options.OutputPath + "/" + options.UpdateChannel.ToString() + "/"; Directory.CreateDirectory(options.OutputPath); Directory.CreateDirectory(outputDir); //Create the version file UpdaterLib.Version version = new UpdaterLib.Version() { Name = b.Version, Channel = options.UpdateChannel, Origin = b.DownloadURL, Notes = b.Notes, BuildDate = b.Date, }; //And insert it into the output Console.WriteLine("Inserting version.txt"); using (ZipFile z = new ZipFile(options.BuildFile)) { z.AddEntry("version.txt", JsonConvert.SerializeObject(version)); string updaterexe = Assembly.GetExecutingAssembly().Location; z.AddFile(updaterexe, ""); z.Save(); } Console.WriteLine("Computing Sha Hash of the build"); //Create the sha hash string hash = ""; using (FileStream stream = File.OpenRead(options.BuildFile)) { SHA256Managed sha = new SHA256Managed(); byte[] h = sha.ComputeHash(stream); hash = BitConverter.ToString(h).Replace("-", String.Empty); } b.Sha = hash; builds.Add(b); Console.WriteLine("Deploying Build"); File.Copy(options.BuildFile, outputDir + Path.GetFileName(options.BuildFile), true); Console.WriteLine("Writing Buildfile"); //Write the builds file File.WriteAllText(buildListFilename, JsonConvert.SerializeObject(builds)); File.WriteAllText(options.OutputPath + "/" + buildListFilename, JsonConvert.SerializeObject(builds)); //Update the manifest man.LastUpdate = b.Date; man.LatestVersion = b.Version; Console.WriteLine("Writing Manifest"); //Write the manifests File.WriteAllText(options.Manifest, JsonConvert.SerializeObject(Manifests)); File.WriteAllText(options.OutputPath + "/" + options.Manifest, JsonConvert.SerializeObject(Manifests)); }
static void CreateBuild(BuilderOptions options) { Console.WriteLine("Creating Build for " + options.UpdateChannel.ToString() + " version " + options.Version); List <Manifest> Manifests; //Get the Manifests if the file exists. If it doesn't, create it if (!File.Exists(options.Manifest)) { Console.WriteLine("Manifest file does not exist, creating Manifests"); CreateDefaultManifests(options); } Manifests = JsonConvert.DeserializeObject <List <Manifest> >(File.ReadAllText(options.Manifest)); //Get the update channel we are building for Manifest man = Manifests.FirstOrDefault(x => x.Channel == options.UpdateChannel.ToString()); if (man == null) { Console.WriteLine("Error: Cannot find the manifest for " + options.Manifest + "! Aborting."); Environment.Exit(0); } //Get the list of builds string buildListFilename = options.UpdateChannel.ToString() + "BuildList.txt"; List <Build> builds = JsonConvert.DeserializeObject <List <Build> >(File.ReadAllText(buildListFilename)); Console.WriteLine("Creating build information"); //Create the build Build b = new Build() { FileName = Path.GetFileName(options.BuildFile), DownloadURL = options.URL + options.UpdateChannel.ToString() + "/", Notes = options.UpdateNotes, DetailURL = options.DetailedNotesURL, Version = options.Version, Date = DateTime.Now, }; Console.WriteLine("Writing Build"); //Copy the file to the output directory string outputDir = options.OutputPath + "/" + options.UpdateChannel.ToString() + "/"; Directory.CreateDirectory(options.OutputPath); Directory.CreateDirectory(outputDir); //Create the version file UpdaterLib.Version version = new UpdaterLib.Version() { Name = b.Version, Channel = options.UpdateChannel, Origin = b.DownloadURL, Notes = b.Notes, BuildDate = b.Date, }; //And insert it into the output Console.WriteLine("Inserting version.txt"); using (ZipFile z = new ZipFile(options.BuildFile)) { z.AddEntry("version.txt", JsonConvert.SerializeObject(version)); string updaterexe = Assembly.GetExecutingAssembly().Location; z.AddFile(updaterexe, ""); z.Save(); } Console.WriteLine("Computing Sha Hash of the build"); //Create the sha hash string hash = ""; using (FileStream stream = File.OpenRead(options.BuildFile)) { SHA256Managed sha = new SHA256Managed(); byte[] h = sha.ComputeHash(stream); hash = BitConverter.ToString(h).Replace("-", String.Empty); } b.Sha = hash; builds.Add(b); Console.WriteLine("Deploying Build"); File.Copy(options.BuildFile, outputDir + Path.GetFileName(options.BuildFile), true); Console.WriteLine("Writing Buildfile"); //Write the builds file File.WriteAllText(buildListFilename, JsonConvert.SerializeObject(builds)); File.WriteAllText(options.OutputPath + "/" + buildListFilename, JsonConvert.SerializeObject(builds)); //Update the manifest man.LastUpdate = b.Date; man.LatestVersion = b.Version; Console.WriteLine("Writing Manifest"); //Write the manifests File.WriteAllText(options.Manifest, JsonConvert.SerializeObject(Manifests)); File.WriteAllText(options.OutputPath + "/" + options.Manifest, JsonConvert.SerializeObject(Manifests)); }