Skip to content

Commit

Permalink
Merge pull request #4 from ali4heydari/fb_Logic
Browse files Browse the repository at this point in the history
Update readme file
  • Loading branch information
ali4heydari committed Dec 1, 2018
2 parents f2ec220 + e8f9026 commit 323a093
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# Telegram2VCF
# Telegram2VCF
[![Build Status](https://dev.azure.com/ali4heydari/AP_19/_apis/build/status/AP_19-.NET%20Desktop-CI)](https://dev.azure.com/ali4heydari/AP_19/_build/latest?definitionId=11)

Easy way to get vcf file of all telegram contact from telegram desktop contact export file (contacs.html)

## Getting Started

### Prerequisites

First you should log in to telegram desktop version 1.4.3


Go to settings -> Advanced -> Export Telegram data.
Check "Contacts list" option and uncheck another then click export button.


### Installing

Just run TelegramToVCF.exe file!

## How to use

Address contacts.html located on \Telegram Desktop\DataExport_XX_XX_XXXX\lists
folder and specify path to save vcf file and then click export button.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnAbout" Grid.Column="0" Margin="3" Content="?"></Button>
<Button x:Name="btnAbout" Grid.Column="0" Margin="3" Content="?" Click="btnAbout_Click"></Button>
<Grid Grid.Column="1" Margin="3">
<ProgressBar x:Name="progressbar" Grid.Column="0" MinHeight="30">
</ProgressBar>
Expand Down
41 changes: 24 additions & 17 deletions TelegramToVCFExporter/TelegramToVCFExporter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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;
Expand All @@ -52,6 +53,7 @@ private void tbxBrowseHtml_Click(object sender, RoutedEventArgs e)

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 @@ -61,9 +63,10 @@ private void tbxBrowseSavePath_Click(object sender, RoutedEventArgs e)
if (savePathFolderBrowserDialog.SelectedPath != String.Empty)
{
this.PathToSave = savePathFolderBrowserDialog.SelectedPath +
$@"\Telegram_Exported_Contacts_{DateTime.Now.Year}_{DateTime.Now.Month}_{
DateTime.Now.Day
}.vcf";
$@"\Telegram_Exported_Contacts_
{DateTime.Now.Year}_
{DateTime.Now.Month}_
{DateTime.Now.Day}.vcf";
Dispatcher.Invoke(
new Action(() => { tbxSavePath.Text = this.PathToSave; }));
Expand All @@ -81,24 +84,23 @@ private void btnExport_Click(object sender, RoutedEventArgs e)
}
else
{
//TODO implement this
throw new Exception("Backgrownd worker is busy");
//TODO tell user an other processes is running
throw new Exception("Background worker is busy");
}
}

void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Dispatcher.Invoke(new Action((() => { progressbar.Value = e.ProgressPercentage; })));
}

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
//TODO run all background tasks here
Dispatcher.Invoke(new Action((() =>
{
progressbar.Foreground = Brushes.Green;
progressbar.Value = e.ProgressPercentage;
lblProgressStatus.Content = $"{e.ProgressPercentage}%";
})));
}

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
Dispatcher.Invoke(new Action((() => { progressbar.Foreground = Brushes.Green; })));

HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();

Expand Down Expand Up @@ -160,34 +162,39 @@ private void worker_DoWork(object sender, DoWorkEventArgs e)

writer.Write(contacts[i].VCF);
writer.Write("\n");
worker.ReportProgress((int) (((i +1)* 1.0 / contacts.Count) * 100));
worker.ReportProgress((int) (((i + 1) * 1.0 / contacts.Count) * 100));
}
}
}

private void worker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
// check error, check cancel, then use result
if (e.Error != null)
{
progressbar.Foreground = Brushes.Red;
lblProgressStatus.Content = $"Error: {e.Error.Message}";
}
else if (e.Cancelled)
{
progressbar.Foreground = Brushes.Yellow;
lblProgressStatus.Content = $"Export canceled by user";
}
else
{

lblProgressStatus.Content = $"Export successful";
}

// general cleanup
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
//TODO ask user really want cancel process
worker.CancelAsync();
}

private void btnAbout_Click(object sender, RoutedEventArgs e)
{
//TODO implement about and contact us
}
}
}

0 comments on commit 323a093

Please sign in to comment.