Skip to content

Commit

Permalink
Merge pull request #5 from ali4heydari/fb_Logic
Browse files Browse the repository at this point in the history
Implement some error checking
  • Loading branch information
ali4heydari committed Dec 5, 2018
2 parents 323a093 + 227e6f1 commit 0b82cb9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</Grid.RowDefinitions>

<Label x:Name="lblSavePath" Grid.Row="0" Grid.Column="0" Content="Path to save:" Margin="3" VerticalAlignment="Center"></Label>
<TextBox x:Name="tbxSavePath" VerticalContentAlignment="Center" Grid.Row="0" Grid.Column="1" Margin="3" Padding="0" TextWrapping="NoWrap" IsReadOnly="True" ></TextBox>
<TextBox x:Name="tbxSavePath" VerticalContentAlignment="Center" Grid.Row="0" Grid.Column="1" Margin="3" Padding="0" TextWrapping="NoWrap" IsReadOnly="True" ></TextBox>
<Button x:Name="tbxBrowseSavePath" Grid.Row="0" Grid.Column="3" Content="Browse..." Margin="3" Click="tbxBrowseSavePath_Click" ></Button>
</Grid>
<Grid Margin="3" Grid.Row="2">
Expand Down
52 changes: 41 additions & 11 deletions TelegramToVCFExporter/TelegramToVCFExporter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.Windows.Media;
using HtmlAgilityPack;
using MessageBox = System.Windows.Forms.MessageBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace TelegramToVCFExporter
Expand Down Expand Up @@ -42,18 +43,21 @@ private void tbxBrowseHtml_Click(object sender, RoutedEventArgs e)
fileDialog.DefaultExt = "html";
fileDialog.InitialDirectory = $@"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}";
fileDialog.ShowDialog();
//TODO if file dose not exit tell user
if (File.Exists(fileDialog.FileName))
{
this.HtmlFilePath = fileDialog.FileName;
Dispatcher.Invoke(new Action(() => { tbxHtml.Text = fileDialog.FileName; }));
}
else
{
MessageBox.Show("File that you selected may move or removed", "File not found",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}).Start();
}

private void tbxBrowseSavePath_Click(object sender, RoutedEventArgs e)
{
//TODO if file with same name exist tell uesr overwrite or not?
var thread = new Thread(((() =>
{
FolderBrowserDialog savePathFolderBrowserDialog = new FolderBrowserDialog();
Expand All @@ -62,11 +66,11 @@ private void tbxBrowseSavePath_Click(object sender, RoutedEventArgs e)
savePathFolderBrowserDialog.ShowDialog();
if (savePathFolderBrowserDialog.SelectedPath != String.Empty)
{
this.PathToSave = savePathFolderBrowserDialog.SelectedPath +
$@"\Telegram_Exported_Contacts_
{DateTime.Now.Year}_
{DateTime.Now.Month}_
{DateTime.Now.Day}.vcf";
string savePath = savePathFolderBrowserDialog.SelectedPath +
$@"\Telegram_Exported_Contacts_{DateTime.Now.Year}_{DateTime.Now.Month}_{
DateTime.Now.Day
}.vcf";
this.PathToSave = savePath;
Dispatcher.Invoke(
new Action(() => { tbxSavePath.Text = this.PathToSave; }));
Expand All @@ -78,14 +82,37 @@ private void tbxBrowseSavePath_Click(object sender, RoutedEventArgs e)

private void btnExport_Click(object sender, RoutedEventArgs e)
{
if (File.Exists(this.PathToSave))
{
DialogResult dialogResult = MessageBox.Show(
"An other file with same name exist on this directory would you like to overwrite it?",
"Overwrite warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (dialogResult == System.Windows.Forms.DialogResult.No)
{
this.PathToSave += "_(1)";
Dispatcher.Invoke(new Action(() => { tbxBrowseSavePath.Content = this.PathToSave; }));
}
else if (dialogResult == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
}

if (!worker.IsBusy)
{
worker.RunWorkerAsync();
}
else
{
//TODO tell user an other processes is running
throw new Exception("Background worker is busy");
DialogResult dialogResult = MessageBox.Show("An other process is running would you like to cancel it?",
"process alter",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

if (dialogResult == System.Windows.Forms.DialogResult.Yes)
{
worker.CancelAsync();
btnExport_Click(sender, e);
}
}
}

Expand Down Expand Up @@ -188,8 +215,11 @@ private void worker_DoWork(object sender, DoWorkEventArgs e)

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
//TODO ask user really want cancel process
worker.CancelAsync();
DialogResult dialogResult = MessageBox.Show("Are you really want to cancel the process?", "Cancel confirm",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (dialogResult == System.Windows.Forms.DialogResult.Yes)
worker.CancelAsync();
}

private void btnAbout_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 0b82cb9

Please sign in to comment.