Change plugin update IO logic

This commit is contained in:
Brant Martin
2019-03-10 16:45:18 -04:00
parent c6121ab590
commit 369a3217f7
2 changed files with 13 additions and 1 deletions

View File

@@ -95,6 +95,10 @@ namespace Torch.API.WebAPI
try try
{ {
path = path ?? $"Plugins\\{item.Name}.zip"; path = path ?? $"Plugins\\{item.Name}.zip";
string relpath = Path.GetDirectoryName(path);
Directory.CreateDirectory(relpath);
var h = await _client.GetAsync(string.Format(PLUGIN_QUERY, item.ID)); var h = await _client.GetAsync(string.Format(PLUGIN_QUERY, item.ID));
string res = await h.Content.ReadAsStringAsync(); string res = await h.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<PluginFullItem>(res); var response = JsonConvert.DeserializeObject<PluginFullItem>(res);
@@ -110,7 +114,11 @@ namespace Torch.API.WebAPI
return false; return false;
} }
var s = await _client.GetStreamAsync(version.URL); var s = await _client.GetStreamAsync(version.URL);
using (var f = new FileStream(path, FileMode.Create))
if(File.Exists(path))
File.Delete(path);
using (var f = File.Create(path))
{ {
await s.CopyToAsync(f); await s.CopyToAsync(f);
await f.FlushAsync(); await f.FlushAsync();

View File

@@ -23,8 +23,12 @@ namespace Torch
/// <summary> /// <summary>
/// A GitHub repository in the format of Author/Repository to retrieve plugin updates. /// A GitHub repository in the format of Author/Repository to retrieve plugin updates.
/// </summary> /// </summary>
[Obsolete("Updates no longer check git. Updates are hosted only on torchapi.net")]
public string Repository { get; set; } public string Repository { get; set; }
//xml tomfoolery
public bool ShouldSerializeRepository() => false;
/// <summary> /// <summary>
/// The plugin version. This must include a string in the format of #[.#[.#]] for update checking purposes. /// The plugin version. This must include a string in the format of #[.#[.#]] for update checking purposes.
/// </summary> /// </summary>