private static void DeleteOutsideAppinfoJsonOnAsset(string id, WebPebbleProject proj) { PebbleProject pproj = new PebbleProject(proj.projectId); //Make sure it is not null. if (pproj.package.pebble.resources == null) { pproj.package.pebble.resources = new Resources(); } if (pproj.package.pebble.resources.media == null) { pproj.package.pebble.resources.media = new List <Medium>(); } //Find it if it exists. for (int i = 0; i < pproj.package.pebble.resources.media.Count; i++) { if (pproj.package.pebble.resources.media[i].x_webpebble_media_id == id) { pproj.package.pebble.resources.media.RemoveAt(i); i--; } } //Save pproj.SavePackage(); }
/// <summary> /// Save the appinfo.json resource data on an asset. This data could come from outside so we must validate it. /// </summary> /// <param name="proj"></param> private static void SaveOutsideAppinfoJsonOnAsset(WebPebbleProjectAsset media, Medium r, WebPebbleProject proj) { PebbleProject pproj = new PebbleProject(proj.projectId); //Make sure it is not null. if (pproj.package.pebble.resources == null) { pproj.package.pebble.resources = new Resources(); } if (pproj.package.pebble.resources.media == null) { pproj.package.pebble.resources.media = new List <Medium>(); } //Find it if it already exists. for (int i = 0; i < pproj.package.pebble.resources.media.Count; i++) { if (pproj.package.pebble.resources.media[i].x_webpebble_media_id == media.id) { pproj.package.pebble.resources.media.RemoveAt(i); i--; } } //Modify. r.file = media.GetRelativePath(); r.x_webpebble_media_id = media.id; //Save pproj.package.pebble.resources.media.Add(r); pproj.SavePackage(); }
public static async Task CheckIfIdentifierExists(Microsoft.AspNetCore.Http.HttpContext e, E_RPWS_User user, WebPebbleProject proj) { //Get the project file and check if the identifier exists. PebbleProject pp = new PebbleProject(proj.projectId); bool exists = pp.package.pebble.resources.media.Find(x => x.name == e.Request.Query["resrc_id"]) != null; CheckIfIdentifierExistsReply reply = new CheckIfIdentifierExistsReply { exists = exists, request_id = e.Request.Query["request_id"] }; await Program.QuickWriteJsonToDoc(e, reply); }
public static async Task AppInfoJson(Microsoft.AspNetCore.Http.HttpContext e, E_RPWS_User user, WebPebbleProject proj) { //Edit or serve appinfo.json. PebbleProject pp = new PebbleProject(proj.projectId); if (e.Request.Method.ToLower() == "get") { await Program.QuickWriteJsonToDoc(e, pp.package); } if (e.Request.Method.ToLower() == "put") { await Program.QuickWriteToDoc(e, "The put endpoint has been disabled due to a security hole.", "text/plain", 404); } }
public static async Task DoCompile(Microsoft.AspNetCore.Http.HttpContext e, E_RPWS_User user, WebPebbleProject proj) { //Compile this Pebble project. PebbleProject pp = new PebbleProject(proj.projectId); //Compile bool ok = pp.DoBuild(out string log); //Generate an ID. if (proj.builds == null) { proj.builds = new List <WebPebbleProjectBuild>(); } string id = LibRpws.LibRpwsCore.GenerateRandomHexString(8); while (proj.builds.Where(x => x.id == id).ToArray().Length != 0) { id = LibRpws.LibRpwsCore.GenerateRandomHexString(8); } //Create the object. WebPebbleProjectBuild b = new WebPebbleProjectBuild(); b.id = id; b.log = log; b.passed = ok; b.time = DateTime.UtcNow.Ticks; //Add this and save proj.builds.Add(b); proj.SaveProject(); //If this build passed, move the pbw into a project folder. Directory.CreateDirectory(Program.config.user_project_build_dir + proj.projectId + "/" + id + "/"); if (ok) { File.Move(pp.pathnane + "build/" + proj.projectId + ".pbw", Program.config.user_project_build_dir + proj.projectId + "/" + id + "/" + "build.pbw"); } //Clean up. try { Directory.Delete(pp.pathnane + "build/", true); } catch { //Huh. Weird. } //Create a reply. await Program.QuickWriteJsonToDoc(e, b); }