Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exiftoolのダウンロードに失敗するのを修正 #41

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion VRCImageHelper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using VRCImageHelper.Core;
using VRCImageHelper.Core.StateChecker;
using VRCImageHelper.Utils;
using VRCImageHelper.Tools;

internal static class Program
{
Expand All @@ -24,11 +25,17 @@ private static void Main()
{
if (args.Contains("--setup"))
{
new UI.DownloadProgressDialog().Download("exiftool", () =>
{
ExifTool.GetExifTool();
return true;
});
new UI.ConfigWindow().ShowDialog();
if (VRCExifWriter.Remove())
return;
var logFile = LogReader.FindLogFile();
if (logFile != null && logFile.Exists && logFile.CreationTime == logFile.LastWriteTime) {
if (logFile != null && logFile.Exists && logFile.CreationTime == logFile.LastWriteTime)
{
UI.SendNotify.Send(Properties.Resources.NotifyErrorLogFileSeemsEmptyOnSetup, false);
}
Process.Start(Application.ExecutablePath);
Expand Down
2 changes: 1 addition & 1 deletion VRCImageHelper/Tools/Executables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static string Download(string fileName, string url, CancellationToken can
Directory.CreateDirectory(destPath);

var archive = new ZipArchive(request.Result);
archive.ExtractToDirectory(destPath);
archive.ExtractToDirectory(destPath, true);

return destPath;
}
Expand Down
8 changes: 6 additions & 2 deletions VRCImageHelper/Tools/ExifTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class ExifTool
public static CancellationToken s_cancellationToken;
private static string? s_exitToolPath;
private static bool s_exitToolDownloading;
private static string GetExifTool()
public static string GetExifTool()
{
while (s_exitToolDownloading)
{
Expand All @@ -37,7 +37,11 @@ private static string CheckExistsAndDownload(string fileName, string url)
if (path is not null) return path;

var dir = Executables.Download(fileName, url, s_cancellationToken);
File.Move(dir + "\\exiftool(-k).exe", dir + "\\exiftool.exe");

var extracted = Directory.GetDirectories(dir).First();

File.Move(extracted + "\\exiftool(-k).exe", dir + "\\exiftool.exe");
Directory.Move(extracted + "\\exiftool_files", dir + "\\exiftool_files");

return dir + "\\exiftool.exe";
}
Expand Down
30 changes: 9 additions & 21 deletions VRCImageHelper/UI/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private void ButtonResetFilePattern_Click(object sender, EventArgs e)
}
}

public delegate void FFMpegDownloadEnd();
private void ComboBoxFileFormat_SelectedIndexChanged(object sender, EventArgs e)
{
var control = (Control)sender;
Expand All @@ -145,29 +144,18 @@ private void ComboBoxFileFormat_SelectedIndexChanged(object sender, EventArgs e)
var res = MessageBox.Show(Resources.FFMpegDownloadMessage, Resources.FFMpegDownloadTitle, MessageBoxButtons.OKCancel);
if (res == DialogResult.OK)
{
var downloadingDialog = new DownloadProgressDialog()
new DownloadProgressDialog().Download("ffmpeg", () =>
{
Text = "Downloading...",
};
var downloading = true;
downloadingDialog.FormClosing += (sender, e) =>
{
if (downloading)
e.Cancel = true;
};
downloadingDialog.Load += (sender, e) =>
{
new Task(() =>
try
{
FFMpeg.Download();
BeginInvoke(new FFMpegDownloadEnd(() =>
{
downloading = false;
downloadingDialog.Close();
}));
}).Start();
};
downloadingDialog.ShowDialog();
return true;
}
catch
{
return false;
}
});
}
}

Expand Down
9 changes: 5 additions & 4 deletions VRCImageHelper/UI/DownloadProgressDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions VRCImageHelper/UI/DownloadProgressDialog.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
namespace VRCImageHelper.UI;
using System.Windows.Forms;
using VRCImageHelper.Properties;

public partial class DownloadProgressDialog : Form
{
public DownloadProgressDialog()
{
InitializeComponent();
}

public delegate void DownloadEnd();
public void Download(string target, Func<bool> download)
{
Text = "Downloading " + target + "...";
var downloading = true;
FormClosing += (sender, e) =>
{
if (downloading)
e.Cancel = true;
};
Load += (sender, e) =>
{
new Task(() =>
{
download();
BeginInvoke(new DownloadEnd(() =>
{
downloading = false;
Close();
}));
}).Start();
};
ShowDialog();
}
}