Skip to content

Commit

Permalink
Merge pull request #8 from murrty/rewrite
Browse files Browse the repository at this point in the history
Version 2 comes with a complete code redo, because i was bored and youtube-dl-gui was pretty laughable up to now.

My main goal is to make this as accessible to as many people as possible; this means that some power-user options aren't available... exception for custom arguments, which allow you to completely set what you want up.

+added better verification
+updated error logging process
+updated settings
+converter fully works
+static youtube-dl & ffmpeg
+better converter process
+more options for converting files, check the settings.
~audio still has a single setting, sorry.
+Summaries in code (for anyone interested)

+ A compatible version of youtube-dl-gui for people who are on, at least, .NET Framework 3.5. This should ensure that it works pre-Windows 7.

Debug changes:
Fixed the custom extensions being saved and removed the custom extension removal confirmation (frmSettings.cs)
Removed WaitForExit for downloading & converting. Makes bulk downloads/conversions easier. (Download.cs Convert.cs)
Changed "* completed" to "* started" for downloading and converting. (frmMain.cs)
Added a check for v.redd.it to fix any corrupted files that may get downloaded (Download.cs frmSettings.cs Downloads.settings)
Added Force-HTTPS for downloading. (Download.cs)
Hid the debug dates & moved the last debug date to the about form (frmMain.cs frmAbout.cs).
  • Loading branch information
murrty1 authored May 31, 2019
2 parents ff46395 + 6b1a914 commit 87e0f8b
Show file tree
Hide file tree
Showing 48 changed files with 4,638 additions and 2,298 deletions.
242 changes: 136 additions & 106 deletions App.config

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Classes/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Text;

internal class Controller {
public const int HWND_BROADCAST = 0xffff;
public static readonly int WM_SHOWFORM = RegisterWindowMessage("WM_SHOWFORM");
public const int HWND_YTDLGUIBROADCAST = 0xffff;
public static readonly int WM_SHOWYTDLGUIFORM = RegisterWindowMessage("WM_SHOWYTDLGUIFORM");
[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32")]
Expand Down
334 changes: 334 additions & 0 deletions Classes/Convert.cs

Large diffs are not rendered by default.

57 changes: 0 additions & 57 deletions Classes/Converter.cs

This file was deleted.

260 changes: 164 additions & 96 deletions Classes/Download.cs

Large diffs are not rendered by default.

73 changes: 39 additions & 34 deletions Classes/ErrorLog.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace youtube_dl_gui {
class ErrorLog {
/// <summary>
/// Reports the error recieved into a MessageBox.
/// Reports any web errors that are caught
/// </summary>
/// <param name="Error">The error string</param>
public static void reportError(string Error) {
if (Advanced.Default.disableErrors)
/// <param name="WebE">The WebException that was caught</param>
/// <param name="url">The URL that (might-have) caused the problem</param>
public static void reportWebError(WebException WebE, string url) {
if (Errors.Default.suppressErrors)
return;

if (MessageBox.Show("An error occured:\n" + Error + "\n\nCopy error to clipboard?", "YChanEx", MessageBoxButtons.YesNo) == DialogResult.Yes)
Clipboard.SetText(Error);
string outputMessage = "A WebException occured while downloading " + url + "\n\n" +
"Inner Exception: " + WebE.InnerException +
"\nStacktrace:" + WebE.StackTrace +
"\n" + WebE.Message +
"\n\n" + WebE.HResult;

if (Errors.Default.detailedErrors) {
System.Windows.Forms.MessageBox.Show(outputMessage, "youtube-dl-gui");
}
else {
System.Windows.Forms.MessageBox.Show("An exception occured while downloading " + url + "\n\n" + WebE.ToString(), "youtube-dl-gui");
}

if (Errors.Default.logErrors) {
System.IO.File.WriteAllText(Environment.CurrentDirectory + "\\error.log", outputMessage);
}
}

/// <summary>
/// Reports the web error with a specific code.
/// Reports any general exceptions that are caught
/// </summary>
/// <param name="webEx">The caught web exception.</param>
/// <param name="url">(Optional) The URL attempting to be downloaded.</param>
public static void reportWebError(WebException webEx, string url = "Not defined") {
if (Advanced.Default.disableErrors)
/// <param name="Exception">The Exception that was caught</param>
public static void reportError(Exception Exception) {
if (Errors.Default.suppressErrors)
return;

var resp = webEx.Response as HttpWebResponse;
int respID = (int)resp.StatusCode;
if (resp != null) {
if (respID == 404) {
MessageBox.Show("404 at URL " + url + "\nThe item was not found.");
}
else if (respID == 403) {
MessageBox.Show("403 at URL " + url + "\nYou do not have access to this.");
}
else if (respID == 500) {
MessageBox.Show("500 at URL " + url + "\nAn error occured on the server. Try again later.");
}
else if (respID == 502) {
MessageBox.Show("502 at URL " + url + "\nBad gateway. Try again later.");
}
else if (respID == 503) {
MessageBox.Show("503 at URL " + url + "\nThe server is temporarily unavailable.\nTry again later, or decrease your downloads");
}
else {
MessageBox.Show(respID + " at URL " + url + "\nThe error is not documented in the source. It's either unrelated or not relevant.\nTry again, either now or later.");
}
string outputMessage = "A general exception has occured.\n\n" +
"Inner Exception: " + Exception.InnerException +
"\nStacktrace:" + Exception.StackTrace +
"\n" + Exception.Message;

if (Errors.Default.detailedErrors) {
System.Windows.Forms.MessageBox.Show(outputMessage, "youtube-dl-gui");
}
else {
System.Windows.Forms.MessageBox.Show("An exception occured\n\n" + Exception.ToString(), "youtube-dl-gui");
}

if (Errors.Default.logErrors) {
System.IO.File.WriteAllText(Environment.CurrentDirectory + "\\error.log", outputMessage);
}
}
}
Expand Down
98 changes: 48 additions & 50 deletions Classes/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ class Updater {
public static string updateFile = @"\ydgu.bat";

public static string getJSON(string url) {
if (!Properties.Settings.Default.jsonSupport)
return null;

try {
using (WebClient wc = new WebClient()) {
wc.Headers.Add("User-Agent: " + Advanced.Default.UserAgent);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
wc.Headers.Add("User-Agent: " + Program.UserAgent);
string json = wc.DownloadString(url);
byte[] bytes = Encoding.ASCII.GetBytes(json);
using (var stream = new MemoryStream(bytes)) {
Expand All @@ -47,7 +51,7 @@ public static string getJSON(string url) {
}
catch (Exception ex) {
Debug.Print(ex.ToString());
ErrorLog.reportError(ex.ToString());
ErrorLog.reportError(ex);
return null;
throw ex;
}
Expand All @@ -67,76 +71,70 @@ public static decimal getCloudVersion() {
}
catch (Exception ex) {
Debug.Print(ex.ToString());
ErrorLog.reportError(ex.ToString());
ErrorLog.reportError(ex);
return -1;
}
}
public static bool isUpdateAvailable(decimal cloudVersion) {
try {
if (Properties.Settings.Default.currentVersion < cloudVersion) {
return true;
}
if (Properties.Settings.Default.appVersion < cloudVersion) { return true; }
else { return false; }
}
catch (Exception ex) {
Debug.Print(ex.ToString());
ErrorLog.reportError(ex.ToString());
ErrorLog.reportError(ex);
return false;
}
}

public static void createUpdaterStub(decimal cloudVersion) {
/*
* This is the entire code for the updater, it is designed to be light-weight and so is batch-based.
"@echo off"
"echo Updating youtube-dl-gui..."
"set upVersion=" + updVersion
"set programName=" + System.AppDomain.CurrentDomain.FriendlyName;
"timeout /t 5 /nobreak"
"del %programName%"
"powershell -Command "(New-Object Net.WebClient).DownloadFile(upateURL + '/%upVersion%/youtube-dl-gui.exe', '%programName%')""
"%programName%"
"exit"
*/
public static bool downloadNewVersion(decimal cloudVersion) {
if (!Properties.Settings.Default.jsonSupport)
return false;

try {
if (File.Exists(Application.StartupPath + updateFile))
File.Delete(Application.StartupPath + updateFile);

File.Create(Application.StartupPath + updateFile).Dispose();
System.IO.StreamWriter writeApp = new System.IO.StreamWriter(Application.StartupPath + updateFile);
writeApp.WriteLine("@echo off");
writeApp.WriteLine("echo Updating youtube-dl-gui...");
writeApp.WriteLine("set upVersion=" + cloudVersion);
writeApp.WriteLine("set programName=" + System.AppDomain.CurrentDomain.FriendlyName);
writeApp.WriteLine("timeout /t 5 /nobreak");
writeApp.WriteLine("del %programName%");
writeApp.WriteLine("powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + downloadURL + "', '%programName%')\"");
writeApp.WriteLine("%programName%");
writeApp.WriteLine("eixt");
writeApp.Close();
using (WebClient wc = new WebClient()) {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
wc.Headers.Add("User-Agent: " + Program.UserAgent);
wc.DownloadFile("https://github.com/murrty/youtube-dl-gui/releases/download/" + (cloudVersion) + "/youtube-dl-gui.exe", Environment.CurrentDirectory + "\\youtube-dl-gui.exe.part");
return true;
}
}
catch (WebException webe) {
ErrorLog.reportWebError(webe, "https://github.com/murrty/youtube-dl-gui/releases/download/this-is-the-detected-updated-version/youtube-dl-gui.exe");
return false;
}
catch (Exception ex) {
Debug.Print(ex.ToString());
ErrorLog.reportError(ex.ToString());
ErrorLog.reportError(ex);
return false;
}
}
public static void runUpdater() {
public static void runMerge() {
Process runUpdater = new Process();
runUpdater.StartInfo.FileName = Environment.CurrentDirectory + "\\youtube-dl-gui-updater.exe";
runUpdater.StartInfo.Arguments = System.AppDomain.CurrentDomain.FriendlyName;
runUpdater.Start();
Environment.Exit(0);
}

public static bool updateStub() {
try {
Process Updater = new Process();
Updater.StartInfo.FileName = System.Windows.Forms.Application.StartupPath + updateFile;
Updater.StartInfo.UseShellExecute = false;
Updater.StartInfo.CreateNoWindow = false;
Properties.Settings.Default.runningUpdate = true;
Updater.Start();
Environment.Exit(0);
if (File.Exists(Environment.CurrentDirectory + "\\youtube-dl-gui-updater.exe")) {
FileVersionInfo stubVersion = FileVersionInfo.GetVersionInfo(Environment.CurrentDirectory + "\\youtube-dl-gui-updater.exe");
if (stubVersion.ProductMajorPart > 1) {
File.Delete(Environment.CurrentDirectory + "\\youtube-dl-gui-updater.exe");
}
else {
return true;
}
}

File.WriteAllBytes(Environment.CurrentDirectory + "\\youtube-dl-gui-updater.exe", Properties.Resources.youtube_dl_gui_updater);

return true;
}
catch (Exception ex) {
Debug.Print(ex.ToString());
ErrorLog.reportError(ex.ToString());
return;
ErrorLog.reportError(ex);
return false;
}
}
}
Expand Down
Loading

0 comments on commit 87e0f8b

Please sign in to comment.