-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace pkhex_egglocke | ||
{ | ||
public class SaveFileGeneratorModel | ||
{ | ||
public int generation { get; set; } = 4; | ||
public string jsonRaw { get; set; } = ""; | ||
public dynamic[] eggs { get; set; } =Array.Empty<dynamic>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Grapevine; | ||
using Newtonsoft.Json; | ||
using PKHeX.Core; | ||
using pkhexEgglocke; | ||
|
||
namespace pkhex_egglocke | ||
{ | ||
[RestResource] | ||
public class MyResource: Resource | ||
{ | ||
[RestRoute("Get", "/api/test")] | ||
public async Task Test(IHttpContext context) | ||
{ | ||
await context.Response.SendResponseAsync("Successfully hit the test route!"); | ||
} | ||
|
||
[RestRoute("Get", "/api/startfile")] | ||
public async Task StartFile(IHttpContext context) | ||
{ | ||
await context.Response.SendResponseAsync("Successfully hit the startfile route!"); | ||
} | ||
|
||
[RestRoute("Get", "/api/file1")] | ||
public async Task DownloadFile(IHttpContext context) | ||
{ | ||
string filePath = "C:\\Users\\Evin Jaff\\Downloads\\Pokemon.mp3"; | ||
|
||
context.Response.ContentType = "audio/mpeg"; | ||
context.Response.AddHeader("Content-Disposition", "attachment; filename=blank.mp3"); | ||
context.Response.ContentLength64 = new FileInfo(filePath).Length; | ||
|
||
await context.Response.SendResponseAsync(File.ReadAllBytes(filePath)); | ||
|
||
} | ||
|
||
[RestRoute("Post", "/api/buildSaveFile")] | ||
public async Task BuildSaveFile(IHttpContext context) | ||
{ | ||
// Decode the input stream | ||
var model = await DeserializeAsync<SaveFileGeneratorModel>(context.Request.InputStream, context.CancellationToken); | ||
|
||
// yields array of dynamic objects | ||
SaveWriter sw = new SaveWriter("C:\\Users\\Evin Jaff\\Downloads\\Blank_SoulSilver.sav"); | ||
|
||
EggCreator[] eggArray = new EggCreator[model.eggs.Length]; | ||
for (int i = 0; i < model.eggs.Length; i++) { | ||
EggCreator constructed_egg_creator = EggCreator.decodeJSON(model.eggs[i].ToString(), false); | ||
sw.addEgg(constructed_egg_creator, i+1); | ||
} | ||
|
||
byte[] saveFile = sw.exportRawBytes(); | ||
|
||
// Prepare the response as a downloadable file | ||
context.Response.ContentType = "application/octet-stream"; | ||
context.Response.AddHeader("Content-Disposition", "attachment; filename=blank.sav"); | ||
context.Response.ContentLength64 = saveFile.Length; | ||
|
||
await context.Response.SendResponseAsync(saveFile); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace pkhex_egglocke | ||
{ | ||
public abstract class Resource | ||
{ | ||
public static JsonSerializerOptions SerializerOptions = new JsonSerializerOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}; | ||
|
||
public async Task<T> DeserializeAsync<T>(Stream stream) | ||
{ | ||
return await DeserializeAsync<T>(stream, CancellationToken.None); | ||
} | ||
|
||
public async Task<T> DeserializeAsync<T>(Stream stream, CancellationToken token) | ||
{ | ||
return await JsonSerializer.DeserializeAsync<T>(stream, SerializerOptions, token); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.