예제 #1
0
        private void RestoreTarget(object sender, RoutedEventArgs e)
        {
            if (Settings.Dirs.Count < 1)
            {
                return;
            }

            DirPair dirPair = null;

            if (grDirs.Visibility == Visibility.Visible)
            {
                dirPair = ((Button)sender).DataContext as DirPair;
                if (dirPair == null)
                {
                    return;
                }
            }
            else
            {
                dirPair = Settings.Dirs[0];
            }

            var dlg = new VistaFolderBrowserDialog();

            dlg.Description         = CoreResources.Ui_Dialogs_RestoreTarget;
            dlg.SelectedPath        = dirPair.Source;
            dlg.ShowNewFolderButton = true;

            bool?result = dlg.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            string targetPath = dlg.SelectedPath;

            _cancellationTokenSource = new CancellationTokenSource();
            _logger.Start();
            Task.Factory
            .StartNew(() =>
            {
                var passwordRuleParser = new PasswordGenerator(Settings.PasswordRule, Settings.CustomPasswordRule, Settings.MasterPassword);
                var zip           = new Zip(passwordRuleParser);
                var fileProcessor = new DirPairProcessor(dirPair, Settings.ArchiveNameRule, false, zip, null, _logger);
                fileProcessor.Unpack(targetPath, _cancellationTokenSource.Token);
            }
                      , _cancellationTokenSource.Token
                      )
            .ContinueWith(LogErrorIfAny, TaskContinuationOptions.OnlyOnFaulted)
            .ContinueWith(o => Dispatcher.Invoke(new Action(() => _logger.Stop())));
        }
예제 #2
0
        private void UpdateTarget(object sender, RoutedEventArgs ea)
        {
            _cancellationTokenSource = new CancellationTokenSource();
            _logger.Start();
            Task.Factory
            .StartNew(() =>
            {
                IEnumerable <DirPair> dirPairs = Settings.HasMultipleDirs
                                                        ? Settings.Dirs
                                                        : Settings.Dirs.Take(1);

                var passwordRuleParser = new PasswordGenerator(Settings.PasswordRule, Settings.CustomPasswordRule, Settings.MasterPassword);
                var zip       = new Zip(passwordRuleParser);
                var thumbnail = Settings.EnableThumbnails
                                                        ? new Thumbnail(Settings)
                                                        : null;

                foreach (DirPair dirPair in dirPairs)
                {
                    try
                    {
                        var fileProcessor = new DirPairProcessor(
                            dirPair, Settings.ArchiveNameRule, Settings.ExcludeFigLeafDir, zip, thumbnail, _logger);
                        fileProcessor.Pack(_cancellationTokenSource.Token, GetCleanTargetConfirm(Settings.ConfirmDelete));
                        if (_cancellationTokenSource.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        LogException(e);
                    }
                }
            },
                      _cancellationTokenSource.Token
                      )
            .ContinueWith(LogErrorIfAny, TaskContinuationOptions.OnlyOnFaulted)
            .ContinueWith(o => Dispatcher.Invoke(new Action(() => _logger.Stop())));
        }
예제 #3
0
        static void Main(string[] args)
        {
            var cmd    = new CommandLineArgs(args);
            var logger = new Logger(cmd.DetailedLogging);

            try
            {
                var settings = Settings.ReadFromFile(false);
                Utils.SetupCulture(settings);
                if (settings == null)
                {
                    logger.Log(false, string.Format(Core.Properties.Resources.Common_ErrorFormat, Core.Properties.Resources.Console_NoSettings));
                }
                else
                {
                    var passwordRuleParser = new PasswordGenerator(settings.PasswordRule, settings.CustomPasswordRule, settings.MasterPassword);
                    var zip = new Zip(passwordRuleParser);

                    if (string.IsNullOrEmpty(cmd.UnpackTarget))
                    {
                        IEnumerable <DirPair> dirPairs = settings.HasMultipleDirs
                                                        ? settings.Dirs
                                                        : settings.Dirs.Take(1);
                        var thumbnail = settings.EnableThumbnails
                                                        ? new Thumbnail(settings)
                                                        : null;

                        foreach (DirPair dirPair in dirPairs)
                        {
                            try
                            {
                                var fileProcessor = new DirPairProcessor(
                                    dirPair, settings.ArchiveNameRule, settings.ExcludeFigLeafDir, zip, thumbnail, logger);
                                fileProcessor.Pack(CancellationToken.None, GetCleanTargetConfirm(settings.ConfirmDelete));
                            }
                            catch (Exception e)
                            {
                                logger.Log(false, string.Format(Core.Properties.Resources.Common_ErrorFormat, e.Message));
                            }
                        }
                    }
                    else
                    {
                        var dirPair = GetUnpackDirPair(cmd, settings, logger);
                        if (dirPair != null)
                        {
                            var fileProcessor = new DirPairProcessor(dirPair, settings.ArchiveNameRule, false, zip, null, logger);
                            fileProcessor.Unpack(cmd.UnpackTarget, CancellationToken.None);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.Log(false, string.Format(Core.Properties.Resources.Common_ErrorFormat, e.Message));
            }

#if DEBUG
            System.Console.WriteLine("Press any key to close..");
            System.Console.Read();
#endif
        }