Open log button now pastes to Teknik

This commit is contained in:
Assistant 2019-12-20 01:25:34 -04:00
parent 193d3a47cc
commit 00581d9166
3 changed files with 69 additions and 4 deletions

View file

@ -25,6 +25,7 @@ namespace ModAssistant
{
public const string BeatSaberAPPID = "620980";
public const string BeatModsAPIUrl = "https://beatmods.com/api/v1/";
public const string TeknikAPIUrl = "https://api.teknik.io/v1/";
public const string BeatModsURL = "https://beatmods.com";
public const string BeatModsModsOptions = "mod?status=approved";
public const string MD5Spacer = " ";
@ -38,6 +39,20 @@ namespace ModAssistant
};
}
public class TeknikPasteResponse
{
public Result result;
public class Result
{
public string id;
public string url;
public string title;
public string syntax;
public DateTime? expiration;
public string password;
}
}
public static void SendNotify(string message, string title = "Mod Assistant")
{
var notification = new System.Windows.Forms.NotifyIcon()

View file

@ -43,6 +43,7 @@
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Management" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />

View file

@ -15,6 +15,9 @@ using System.Windows.Shapes;
using System.Globalization;
using System.IO;
using Path = System.IO.Path;
using System.Net;
using System.Web.Script.Serialization;
using System.Web;
namespace ModAssistant.Pages
{
@ -34,8 +37,7 @@ namespace ModAssistant.Pages
public bool ModelSaberProtocolHandlerEnabled { get; set; }
public bool BeatSaverProtocolHandlerEnabled { get; set; }
public bool ModSaberProtocolHandlerEnabled { get; set; }
public string LogURL { get; private set; }
public Options()
{
@ -149,9 +151,56 @@ namespace ModAssistant.Pages
Properties.Settings.Default.Save();
}
private void OpenLogsDirButton_Click(object sender, RoutedEventArgs e)
private async void OpenLogsDirButton_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start(Path.Combine(InstallDirectory, "Logs"));
try
{
MainWindow.Instance.MainText = "Uploading Log...";
await Task.Run(() => UploadLog());
System.Diagnostics.Process.Start(LogURL);
Clipboard.SetText(LogURL);
MainWindow.Instance.MainText = "Log URL Copied To Clipboard!";
}
catch (Exception exception)
{
MainWindow.Instance.MainText = "Uploading Log Failed.";
MessageBox.Show("Could not upload log file to Teknik, please try again or send the file manually.\n ================= \n" + exception, "Uploading log failed!");
System.Diagnostics.Process.Start(Path.Combine(InstallDirectory, "Logs"));
}
}
private void UploadLog()
{
const string DateFormat = "yyyy-mm-dd HH:mm:ss";
DateTime now = DateTime.Now;
Utils.TeknikPasteResponse TeknikResponse;
string postData =
"title=" + "_latest.log (" + now.ToString(DateFormat) + ")" +
"&expireUnit=hour&expireLength=5" +
"&code=" + HttpUtility.UrlEncode(File.ReadAllText(Path.Combine(InstallDirectory, "Logs", "_latest.log")));
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.TeknikAPIUrl + "Paste");
request.AutomaticDecompression = DecompressionMethods.GZip;
request.UserAgent = "ModAssistant/" + App.Version;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
using (WebResponse response = (WebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
var serializer = new JavaScriptSerializer();
TeknikResponse = serializer.Deserialize<Utils.TeknikPasteResponse>(reader.ReadToEnd());
}
LogURL = TeknikResponse.result.url;
}
private async void YeetBSIPAButton_Click(object sender, RoutedEventArgs e)