You can now release builds from the dev CP.

This commit is contained in:
Michael 2017-04-05 20:24:19 -04:00
parent 371fb31867
commit ae757d47d5
4 changed files with 156 additions and 4 deletions

View file

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Project_Unite.Models; using Project_Unite.Models;
namespace Project_Unite.Controllers namespace Project_Unite.Controllers
@ -22,5 +24,104 @@ namespace Project_Unite.Controllers
var db = new ApplicationDbContext(); var db = new ApplicationDbContext();
return View(db.Downloads); 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");
} }
} }
}

View file

@ -42,21 +42,23 @@ namespace Project_Unite.Models
public class PostDownloadViewModel public class PostDownloadViewModel
{ {
[Required] [Required(ErrorMessage = "You must name your build!")]
public string Name { get; set; } 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 HttpPostedFileBase Screenshot { get; set; }
public string DevUpdateId { get; set; } public string DevUpdateId { get; set; }
[Required] [Required(ErrorMessage ="Well, is it a beta or not?")]
public bool IsStable { get; set; } public bool IsStable { get; set; }
[Required] [Required(ErrorMessage ="Can you...describe the build?")]
[AllowHtml] [AllowHtml]
public string Changelog { get; set; } 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)] [DataType(DataType.Upload)]
public HttpPostedFileBase Download { get; set; } public HttpPostedFileBase Download { get; set; }

View file

@ -540,6 +540,7 @@
<Content Include="Views\Wiki\Index.cshtml" /> <Content Include="Views\Wiki\Index.cshtml" />
<Content Include="Views\Developer\Index.cshtml" /> <Content Include="Views\Developer\Index.cshtml" />
<Content Include="Views\Developer\Releases.cshtml" /> <Content Include="Views\Developer\Releases.cshtml" />
<Content Include="Views\Developer\AddRelease.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />

View file

@ -0,0 +1,48 @@
@model Project_Unite.Models.PostDownloadViewModel
@{
ViewBag.Title = "Add release";
}
<h2>Add release</h2>
<p>Ready to release a new build of ShiftOS? It's never been easier. Just fill out this form:</p>
@using (Html.BeginForm("AddRelease", "Developer", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="panel panel-danger">
@Html.ValidationSummary()
</div>
@Html.AntiForgeryToken()
<table class="table">
<tr>
<td style="width:35%;"><strong>Title:</strong>
<p>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, <strong>ShiftOS 1.0 Beta 1.4</strong></p>
</td>
<td>@Html.TextBoxFor(Model => Model.Name, new { @class = "form-control" })</td>
</tr>
<tr>
<td><strong>Screenshot</strong><br />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.</td>
<td>@Html.TextBoxFor(Model => Model.Screenshot, new { @class = "form-control", type="file" })</td>
</tr>
<tr>
<td><strong>Changelog/Build description:</strong><br />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! <strong>Markdown is supported.</strong></td>
<td>@Html.TextAreaFor(Model => Model.Changelog, new { rows = "5", @class = "form-control" })</td>
</tr>
<tr>
<td><strong>Development update YouTube ID:</strong><br/>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.</td>
<td>@Html.TextBoxFor(Model=>Model.DevUpdateId, new { @class = "form-control" })</td>
</tr>
<tr>
<td><strong>Download:</strong><br />This is the actual release. Simply upload a .ZIP file containing all .dll and .exe files found in your ShiftOS bin/Debug folder.</td>
<td>@Html.TextBoxFor(Model => Model.Download, new { @class = "form-control", type = "file" })</td>
</tr>
<tr>
<td><strong>Is it stable?</strong><br />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... :)</td>
<td>@Html.CheckBoxFor(Model => Model.IsStable, new { @class = "form-control" })</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Release!" class="btn btn-primary" /></td>
</tr>
</table>
}