Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit e321279

Browse files
committed
Improves existing file warnings
1 parent f61648d commit e321279

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

WPFMETRO/Localization/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WPFMETRO/Localization/Strings.pt-BR.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@
138138
<data name="AlertOnFinish" xml:space="preserve">
139139
<value>Alertar ao Fim</value>
140140
</data>
141+
<data name="AlreadyDownloaded" xml:space="preserve">
142+
<value>Este vídeo já foi baixado com este nome de arquivo</value>
143+
</data>
141144
<data name="AreYouSure" xml:space="preserve">
142145
<value>Você tem certeza?</value>
143146
</data>

WPFMETRO/Localization/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@
138138
<data name="AlertOnFinish" xml:space="preserve">
139139
<value>Alert on Finish</value>
140140
</data>
141+
<data name="AlreadyDownloaded" xml:space="preserve">
142+
<value>File has already been downloaded under this file name</value>
143+
</data>
141144
<data name="AreYouSure" xml:space="preserve">
142145
<value>Are you sure?</value>
143146
</data>

WPFMETRO/MainWindow.xaml.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ private async void SelectButton_Click(object sender, RoutedEventArgs e)
152152
DownloadStatus.Text = Localization.Strings.RetrevingFormats;
153153

154154
await Task.Run(() => formats=queue.GetFormats(Url));
155-
await Task.Run(() => videoInfo = queue.GetInfo(Url));
155+
await Task.Run(() => videoInfo=queue.GetInfo(Url));
156156

157157
if (formats.Count > 0)
158158
{
159159
FiletypeBox.IsEnabled = AddToQueueButton.IsEnabled = true;
160160
UrlBox.Background = Brushes.DarkGreen;
161-
FiletypeBox.SelectedIndex = 0;
161+
FiletypeBox.SelectedItem = formats.First();
162162
}
163163
else
164164
{
@@ -328,6 +328,27 @@ private void AddToQueueButton_Click(object sender, RoutedEventArgs e)
328328
string title = videoInfo[0];
329329
string thumbURL = videoInfo[1] == "N.A" ? null : videoInfo[1];
330330

331+
if (filetype == null)
332+
{
333+
MessageBox.Show(Localization.Strings.PleaseSelectFormat);
334+
return;
335+
}
336+
337+
string fullpath = filename == "%(title)s.%(ext)s" ? path + title + "." : path + filename + ".";
338+
fullpath += formats[filetype].Contains(' ') ? formats[filetype].Substring(0, formats[filetype].IndexOf(' ')) : formats[filetype];
339+
if (File.Exists(fullpath))
340+
{
341+
MessageBoxResult userDialogResult = MessageBox.Show(Localization.Strings.FileExists, Localization.Strings.Error, MessageBoxButton.YesNo, MessageBoxImage.Warning);
342+
if (userDialogResult == MessageBoxResult.Yes)
343+
{
344+
File.Delete(fullpath);
345+
}
346+
else
347+
{
348+
return;
349+
}
350+
}
351+
331352
DownloadStatus.Text = Localization.Strings.GettingTitle;
332353

333354
queue.ModifyQueue(title, thumbURL, ID, filename, path, filetype, formats);

WPFMETRO/Queue.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,6 @@ public void DownloadChannel(string ID, string filename, string path, string file
220220

221221
public void ModifyQueue(string title, string thumbURL, string ID, string filename, string path, string filetype, Dictionary<string, string> formats)
222222
{
223-
if(filetype == null)
224-
{
225-
MessageBox.Show(Localization.Strings.PleaseSelectFormat);
226-
return;
227-
}
228-
229-
string fullpath = filename == "%(title)s.%(ext)s" ? path + title + "." + formats[filetype] : path + filename + "." + formats[filetype];
230-
if (File.Exists(fullpath))
231-
{
232-
MessageBoxResult userDialogResult = MessageBox.Show(Localization.Strings.FileExists, Localization.Strings.Error, MessageBoxButton.YesNo, MessageBoxImage.Warning);
233-
if(userDialogResult == MessageBoxResult.Yes)
234-
{
235-
File.Delete(fullpath);
236-
}
237-
else
238-
{
239-
return;
240-
}
241-
}
242223
if (ID.Contains("youtu.be/") || ID.Contains("youtube.com/"))
243224
{
244225
if (ID.Contains("playlist"))

WPFMETRO/Video.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public void DownloadVideo()
8686
{
8787
output = f.Data ?? "null";
8888

89+
if(output.Contains("has already been downloaded"))
90+
{
91+
MessageBox.Show(Localization.Strings.AlreadyDownloaded, Localization.Strings.Error);
92+
completedDownload = true;
93+
}
94+
8995
if (output.Contains("[download]") && output.Contains("of"))
9096
{
9197
if (output.Contains("at") && output.Contains("MiB") && !output.Contains("Destination"))

0 commit comments

Comments
 (0)