public MainWindow()
        {
            InitializeComponent();

            _fileDiver = new FileDiver();

            App.LanguageChanged += LanguageChanged;

            CultureInfo currentLanguage = App.Language;
            foreach (var language in App.Languages)
            {
                var menuItem = new MenuItem
                {
                    Header = language.DisplayName,
                    Tag = language,
                    IsChecked = Equals(currentLanguage)
                };
                menuItem.Click += ChangeLanguageClick;
                LanguageMenu.Items.Add(menuItem);
            }

            if (!File.Exists(DbHelper.DbPath))
            {
                DbHelper.CreateDb();
                DbHelper.CreateReadedFilesTable();
            }

            try
            {
                MainWindowX.WindowStartupLocation = WindowStartupLocation.Manual;

                _tokenSource = new CancellationTokenSource();
                _searchEngine = new SearchEngine();
                CbDrives.ItemsSource = Directory.GetLogicalDrives();

                CbDrives.SelectedIndex = 0;

                InitExplorer();
            }
            catch (IOException ioException)
            {
                var messageDialog = new MessageDialog(ioException.Message)
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner,
                    Owner = this
                };
                messageDialog.ShowDialog();
            }
            catch (UnauthorizedAccessException unauthorizedAccessException)
            {
                var messageDialog = new MessageDialog(unauthorizedAccessException.Message)
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner,
                    Owner = this
                };
                messageDialog.ShowDialog();
            }
        }
 private async void RemoveExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (ListViewExplorer.SelectedItems.Count <= 0) return;
     await PbVisualization.TogglePbVisibilityAsync();
     var fsEntries = ListViewExplorer.SelectedItems;
     if (fsEntries != null)
     {
         var messageDialog = new MessageDialog(Properties.Resources.MwRemoveDialogText,
             Properties.Resources.MwRemoveDialogTitle,
             MessageDialogButtons.YesNo)
         {
             WindowStartupLocation = WindowStartupLocation.CenterOwner,
             Owner = this
         };
         messageDialog.ShowDialog();
         if (messageDialog.MessageDialogResult != MessageDialogResult.Yes)
         {
             await PbVisualization.TogglePbVisibilityAsync();
             return;
         }
         try
         {
             await Task.Factory.StartNew(async () =>
             {
                 foreach (FileSystemInfo entry in fsEntries)
                 {
                     try
                     {
                         string entryPath = entry.FullName;
                         await DbHelper.RemoveReadedFile(entryPath);
                         if (entry.IsDirectory())
                         {
                             await Task.Factory.StartNew(() =>
                             {
                                 Directory.Delete(entryPath, true);
                             });
                         }
                         else
                         {
                             entry.Delete();
                         }
                         
                     }
                     catch (Exception)
                     {
                         Dispatcher.InvokeAsync(() =>
                         {
                             ErrorPopup.IsOpen = true;
                             SystemSounds.Exclamation.Play();
                         });
                     }
                 }
             });
         }
         catch (Exception)
         {
             ErrorPopup.IsOpen = true;
             SystemSounds.Exclamation.Play();
         }
     }
     ListViewExplorer_Refresh();
     await PbVisualization.TogglePbVisibilityAsync();
 }
        private void AppDeployOnCheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs args)
        {
            if (args.Error != null)
            {
                var messageDialog = new MessageDialog(Properties.Resources.MwDeploymentDownloadException + args.Error.Message)
                {
                    Owner = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                messageDialog.ShowDialog();
                return;
            }
            if (args.Cancelled)
            {
                _updateDialog.Close();
                return;
            }

            if (args.UpdateAvailable)
            {
                var messageDialog = new MessageDialog(Properties.Resources.MwUpdateDialogContentBeforeVersion +
                                                   args.AvailableVersion +
                                                   Properties.Resources.MwUpdateDialogContentAfterVersion,
                    Properties.Resources.MwUpdateDialogHeader, MessageDialogButtons.YesNo)
                {
                    Owner = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                messageDialog.ShowDialog();

                if (messageDialog.MessageDialogResult == MessageDialogResult.Yes)
                {
                    _updateDialog.PbDownloadProgress.Value = 0;
                    BeginUpdate();
                }
                else
                {
                    _updateDialog.Close();
                }
            }
            else
            {
                var messageDialog = new MessageDialog(Properties.Resources.MwNoUpdatesText,
                    Properties.Resources.MwNoUpdatesHeader, MessageDialogButtons.Ok)
                {
                    Owner = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                messageDialog.ShowDialog();
                _updateDialog.Close();
            }
        }
        private void CheckForUpdates()
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                _appDeploy = ApplicationDeployment.CurrentDeployment;
                _updateDialog = new UpdateDialog
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner,
                    Owner = this,
                    TbUpdateStage = {Text = Properties.Resources.UdUpdateStageCheck},
                    Title = Properties.Resources.UdUpdateStageUpdating,
                    AppDeploy = _appDeploy
                };
                _appDeploy.CheckForUpdateProgressChanged -= AppDeployOnCheckForUpdateProgressChanged;
                _appDeploy.CheckForUpdateProgressChanged += AppDeployOnCheckForUpdateProgressChanged;
                _appDeploy.CheckForUpdateCompleted -= AppDeployOnCheckForUpdateCompleted;
                _appDeploy.CheckForUpdateCompleted += AppDeployOnCheckForUpdateCompleted;

                try
                {
                    _appDeploy.CheckForUpdateAsync();
                    _updateDialog.ShowDialog();
                }
                catch (DeploymentDownloadException dde)
                {
                    var messageDialog = new MessageDialog(Properties.Resources.MwDeploymentDownloadException + dde.Message)
                    {
                        Owner = this,
                        WindowStartupLocation = WindowStartupLocation.CenterOwner
                    };
                    messageDialog.ShowDialog();
                }
                catch (InvalidDeploymentException ide)
                {
                    var messageDialog = new MessageDialog(Properties.Resources.MwInvalidDeploymentException + ide.Message)
                    {
                        Owner = this,
                        WindowStartupLocation = WindowStartupLocation.CenterOwner
                    };
                    messageDialog.ShowDialog();
                }
                catch (InvalidOperationException ioe)
                {
                    var messageDialog = new MessageDialog(Properties.Resources.MwInvalidOperationException + ioe.Message)
                    {
                        Owner = this,
                        WindowStartupLocation = WindowStartupLocation.CenterOwner
                    };
                    messageDialog.ShowDialog();
                }
            }
            else
            {
                var messageDialog = new MessageDialog(Properties.Resources.MwWrongAppUpdate)
                {
                    Owner = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                messageDialog.ShowDialog();
            }
        }
        private void AppDeployOnUpdateCompleted(object sender, AsyncCompletedEventArgs args)
        {
            if (args.Error != null)
            {
                var messageDialog = new MessageDialog(Properties.Resources.MwDeploymentDownloadException + args.Error.Message)
                {
                    Owner = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                messageDialog.ShowDialog();
                return;
            }
            if (args.Cancelled)
            {
                _updateDialog.Close();
                return;
            }

            var mDialog = new MessageDialog(Properties.Resources.MwAppUpdatedText,
                Properties.Resources.MwAppUpdatedHeader, MessageDialogButtons.Ok)
            {
                Owner = this,
                WindowStartupLocation = WindowStartupLocation.CenterOwner
            };
            mDialog.ShowDialog();
            _updateDialog.Close();
        }
 private void BeginUpdate()
 {
     _appDeploy = ApplicationDeployment.CurrentDeployment;
     _updateDialog.TbUpdateStage.Text = Properties.Resources.UdUpdateStageUpdating;
     _updateDialog.Title = Properties.Resources.UdUpdateStageUpdating;
     _appDeploy.UpdateCompleted -= AppDeployOnUpdateCompleted;
     _appDeploy.UpdateCompleted += AppDeployOnUpdateCompleted;
     _appDeploy.UpdateProgressChanged -= AppDeployOnUpdateProgressChanged;
     _appDeploy.UpdateProgressChanged += AppDeployOnUpdateProgressChanged;
     try
     {
         _appDeploy.UpdateAsync();
     }
     catch (DeploymentDownloadException dde)
     {
         var messageDialog = new MessageDialog(Properties.Resources.MwDeploymentDownloadException + dde.Message)
         {
             Owner = this,
             WindowStartupLocation = WindowStartupLocation.CenterOwner
         };
         messageDialog.ShowDialog();
     }
     catch (InvalidDeploymentException ide)
     {
         var messageDialog = new MessageDialog(Properties.Resources.MwInvalidDeploymentException + ide.Message)
         {
             Owner = this,
             WindowStartupLocation = WindowStartupLocation.CenterOwner
         };
         messageDialog.ShowDialog();
     }
     catch (InvalidOperationException ioe)
     {
         var messageDialog = new MessageDialog(Properties.Resources.MwInvalidOperationException + ioe.Message)
         {
             Owner = this,
             WindowStartupLocation = WindowStartupLocation.CenterOwner
         };
         messageDialog.ShowDialog();
     }
 }