From ae757d47d51a57f83a43a527481d01f63b9fc741 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 5 Apr 2017 20:24:19 -0400 Subject: [PATCH] You can now release builds from the dev CP. --- .../Controllers/DeveloperController.cs | 101 ++++++++++++++++++ Project-Unite/Models/Download.cs | 10 +- Project-Unite/Project-Unite.csproj | 1 + .../Views/Developer/AddRelease.cshtml | 48 +++++++++ 4 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 Project-Unite/Views/Developer/AddRelease.cshtml diff --git a/Project-Unite/Controllers/DeveloperController.cs b/Project-Unite/Controllers/DeveloperController.cs index b380acb..0825eb1 100644 --- a/Project-Unite/Controllers/DeveloperController.cs +++ b/Project-Unite/Controllers/DeveloperController.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers @@ -22,5 +24,104 @@ namespace Project_Unite.Controllers var db = new ApplicationDbContext(); return View(db.Downloads); } + + public ActionResult AddRelease() + { + if (!ACL.Granted(User.Identity.Name, "CanReleaseBuilds")) + return new HttpStatusCodeResult(403); + ViewBag.Developer = true; + + var build = new PostDownloadViewModel(); + return View(build); + } + + const string ApprovedIdChars = ".-_abcdefghijklmnopqrstuvwxyz1234567890"; + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult AddRelease(PostDownloadViewModel model) + { + if (!ACL.Granted(User.Identity.Name, "CanReleaseBuilds")) + return new HttpStatusCodeResult(403); + if (!ModelState.IsValid) + return View(model); + + //Create a new database context. + var db = new ApplicationDbContext(); + + //Create a new "Download" data object + var download = new Download(); + //Set the ID. + string new_id = model.Name.ToLower(); + + foreach(var c in new_id.ToCharArray()) + { + if (!ApprovedIdChars.Contains(c)) + new_id = new_id.Replace(c, '_'); + } + new_id += "_" + db.Downloads.Count().ToString(); + download.Id = new_id; + //Set the name. + download.Name = model.Name; + //Set the author + download.ReleasedBy = User.Identity.GetUserId(); + //Set the time + download.PostDate = DateTime.Now; + + //Can't forget the changelog. Literally, I almost forgot. + download.Changelog = model.Changelog; + + //Set the YT ID + download.DevUpdateId = model.DevUpdateId; + + //Set whether the build is stable + download.IsStable = model.IsStable; + + //We're not obsolete. + download.Obsolete = false; + + //Now we upload the download. + + string download_dir = "~/Uploads/Releases/"; + string mapped_dir = Server.MapPath(download_dir); + if (!Directory.Exists(mapped_dir)) + Directory.CreateDirectory(mapped_dir); + + string file_name_d = model.Download.FileName; + foreach(var c in file_name_d.ToCharArray()) + { + if (!ApprovedIdChars.Contains(c)) + file_name_d = file_name_d.Replace(c, '_'); + } + download_dir += file_name_d; + mapped_dir = Server.MapPath(download_dir); + download.DownloadUrl = download_dir; + //Now the download is saved in the DB. Let's get it on the server. + model.Download.SaveAs(mapped_dir); + + download_dir = "~/Uploads/Releases/Screenshots/"; + mapped_dir = Server.MapPath(download_dir); + if (!Directory.Exists(mapped_dir)) + Directory.CreateDirectory(mapped_dir); + + file_name_d = model.Screenshot.FileName; + foreach (var c in file_name_d.ToCharArray()) + { + if (!ApprovedIdChars.Contains(c)) + file_name_d = file_name_d.Replace(c, '_'); + } + download_dir += file_name_d; + mapped_dir = Server.MapPath(download_dir); + download.ScreenshotUrl = download_dir; + model.Screenshot.SaveAs(mapped_dir); + + //Now we just save to the database... + db.Downloads.Add(download); + db.SaveChanges(); + + return RedirectToAction("Releases"); + } } + + } \ No newline at end of file diff --git a/Project-Unite/Models/Download.cs b/Project-Unite/Models/Download.cs index 1dcf2bb..2216507 100644 --- a/Project-Unite/Models/Download.cs +++ b/Project-Unite/Models/Download.cs @@ -42,21 +42,23 @@ namespace Project_Unite.Models public class PostDownloadViewModel { - [Required] + [Required(ErrorMessage = "You must name your build!")] public string Name { get; set; } + [Required(ErrorMessage ="A screenshot is necessary for getting users into the game.")] + [DataType(DataType.Upload)] public HttpPostedFileBase Screenshot { get; set; } public string DevUpdateId { get; set; } - [Required] + [Required(ErrorMessage ="Well, is it a beta or not?")] public bool IsStable { get; set; } - [Required] + [Required(ErrorMessage ="Can you...describe the build?")] [AllowHtml] public string Changelog { get; set; } - [Required] + [Required(ErrorMessage ="We can't just pull a download out of thin air! Please, upload a release.")] [DataType(DataType.Upload)] public HttpPostedFileBase Download { get; set; } diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 6e70675..afb2d1d 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -540,6 +540,7 @@ + diff --git a/Project-Unite/Views/Developer/AddRelease.cshtml b/Project-Unite/Views/Developer/AddRelease.cshtml new file mode 100644 index 0000000..dbeaa3b --- /dev/null +++ b/Project-Unite/Views/Developer/AddRelease.cshtml @@ -0,0 +1,48 @@ +@model Project_Unite.Models.PostDownloadViewModel +@{ + ViewBag.Title = "Add release"; +} + +

Add release

+ +

Ready to release a new build of ShiftOS? It's never been easier. Just fill out this form:

+ +@using (Html.BeginForm("AddRelease", "Developer", null, FormMethod.Post, new { enctype = "multipart/form-data" })) +{ +
+ @Html.ValidationSummary() +
+ @Html.AntiForgeryToken() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title: +

This is the title of the build. It should contain the major and minor build numbers, release status ("alpha", "beta", "RC", etc), build number, and revision. For example, ShiftOS 1.0 Beta 1.4

+
@Html.TextBoxFor(Model => Model.Name, new { @class = "form-control" })
Screenshot
A screenshot can give potential players an idea of what's going on in this build. Be sure to show key features, key UI changes, etc.
@Html.TextBoxFor(Model => Model.Screenshot, new { @class = "form-control", type="file" })
Changelog/Build description:
When users view full details about this build, these are the details shown. Try to include a list of new features, a list of bugs, and a list of bugfixes. You can also post additional screenshots, videos, etc here. Make this build shine! Markdown is supported.
@Html.TextAreaFor(Model => Model.Changelog, new { rows = "5", @class = "form-control" })
Development update YouTube ID:
If you or another dev has done a ShiftOS dev update on the YouTube channel for this release, paste its video ID here. You can get it by browsing the video and copying the text immediately after the "watch?v=" in the video URL.
@Html.TextBoxFor(Model=>Model.DevUpdateId, new { @class = "form-control" })
Download:
This is the actual release. Simply upload a .ZIP file containing all .dll and .exe files found in your ShiftOS bin/Debug folder.
@Html.TextBoxFor(Model => Model.Download, new { @class = "form-control", type = "file" })
Is it stable?
If this build has no known bugs, then check this value. Usually it'd be the lead dev making stables but as long as I approve, you can as well. I mean, unless you're me, in which case it's your site... do what you want, future Michael! I hope you also finished all your homework. And I hope you got a good French mark... :)
@Html.CheckBoxFor(Model => Model.IsStable, new { @class = "form-control" })
+} \ No newline at end of file