private void OpenArchive(string path, Action <PaneViewModelBase> success, Action <PaneViewModelBase, Exception> error, string password = null)
 {
     WorkHandler.Run(
         () =>
     {
         FileManager.Open(path, password);
         return(true);
     },
         result =>
     {
         IsLoaded = true;
         Initialize();
         Drive = Drives.First();
         if (success != null)
         {
             success.Invoke(this);
         }
     },
         exception =>
     {
         if (exception is PasswordProtectedException)
         {
             //var pwd = WindowManager.ShowTextInputDialog(Resx.PasswordRequired, Resx.PleaseEnterAPassword, string.Empty, null);
             //if (!string.IsNullOrEmpty(pwd))
             //{
             //    OpenArchive(path, success, error, password);
             //    return;
             //}
         }
         if (error != null)
         {
             error.Invoke(this, exception);
         }
     });
 }
Example #2
0
 public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null)
 {
     base.LoadDataAsync(cmd, cmdParam, success, error);
     switch (cmd)
     {
     case LoadCommand.Load:
     case LoadCommand.Extract:
     case LoadCommand.Convert:
         WorkHandler.Run(
             () =>
         {
             FileManager.Load((string)cmdParam.Payload);
             return(true);
         },
             result =>
         {
             IsLoaded = true;
             Initialize();
             Drive = Drives.First();
             if (success != null)
             {
                 success.Invoke(this);
             }
         },
             exception =>
         {
             if (error != null)
             {
                 error.Invoke(this, exception);
             }
         });
         break;
     }
 }
 public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null)
 {
     base.LoadDataAsync(cmd, cmdParam, success, error);
     switch (cmd)
     {
     case LoadCommand.Load:
         WorkHandler.Run(
             () =>
         {
             _packageContent = (BinaryContent)cmdParam.Payload;
             _stfs           = ModelFactory.GetModel <StfsPackage>(_packageContent.Content);
             return(true);
         },
             result =>
         {
             IsLoaded = true;
             Tabs.Add(new ProfileRebuilderTabItemViewModel(Resx.FileStructure, ParseStfs(_stfs)));
             SelectedTab = Tabs.First();
             if (success != null)
             {
                 success.Invoke(this);
             }
         },
             exception =>
         {
             if (error != null)
             {
                 error.Invoke(this, exception);
             }
         });
         break;
     }
 }
        private void ExecuteNewFolderCommand()
        {
            var items      = SourcePane.Items.Select(item => item.Name).ToList();
            var wkDirs     = DirectoryStructure.WellKnownDirectoriesOf(SourcePane.CurrentFolder.Path);
            var suggestion = wkDirs.Where(d => !items.Contains(d)).Select(d => new InputDialogOptionViewModel
            {
                Value       = d,
                DisplayName = TitleRecognizer.GetTitle(d)
            }).ToList();

            var name = WindowManager.ShowTextInputDialog(Resx.AddNewFolder, Resx.FolderName + Strings.Colon, string.Empty, suggestion);

            if (name == null)
            {
                return;
            }
            name = name.Trim();
            if (name == string.Empty)
            {
                WindowManager.ShowMessage(Resx.AddNewFolder, Resx.CannotCreateFolderWithNoName);
                return;
            }
            //var invalidChars = Path.GetInvalidFileNameChars();
            //if (invalidChars.Any(name.Contains))
            //{
            //    WindowManager.ShowMessage(Resx.AddNewFolder, Resx.CannotCreateFolderWithInvalidCharacters);
            //    return;
            //}
            var path = string.Format("{0}{1}", SourcePane.CurrentFolder.Path, name);

            WorkHandler.Run(() => SourcePane.CreateFolder(path), result => NewFolderSuccess(result, name), NewFolderError);
        }
 private void ExecuteMergeCommand(object cmdParam)
 {
     _otherPath = @"..\..\..\..\Resources\mergeable\E0000027FA233BE2";
     //_otherPath = @"..\..\..\..\Resources\newmergeapproach\E00001D5D85ED487.0114";
     LoadSubscribe();
     WorkHandler.Run(Merge, MergeCallback);
 }
Example #6
0
 private void ExecuteClearCacheCommand()
 {
     WorkHandler.Run(() =>
     {
         WindowManager.ShowMessage(Resx.ApplicationIsBusy, Resx.PleaseWait, NotificationMessageFlags.NonClosable);
         _cacheManager.Clear();
         return(true);
     },
                     r => WindowManager.CloseMessage());
 }
        public override void LoadDataAsync(LoadCommand cmd, object cmdParam)
        {
            switch (cmd)
            {
            case LoadCommand.Load:
                _path = (string)cmdParam;
                LoadSubscribe();
                WorkHandler.Run(LoadFile, LoadFileCallback);
                break;

            case LoadCommand.MergeWith:
                //_profile.MergeWith((StfsPackage)cmdParam);
                break;
            }
        }
Example #8
0
        public void ConvertToGod(string targetPath)
        {
            var viewModel = new GodConversionSettingsViewModel(targetPath, FileManager.Details, WindowManager);

            if (!WindowManager.ShowGodConversionSettingsDialog(viewModel))
            {
                return;
            }

            ProgressMessage = Resx.StartingIsoConversion + Strings.DotDotDot;
            ProgressValue   = 0;
            this.NotifyProgressStarted();

            WorkHandler.Run(() => ConvertToGodAsync(viewModel), ConvertToGodSuccess, ConvertToGodError);
        }
Example #9
0
        public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null)
        {
            base.LoadDataAsync(cmd, cmdParam, success, error);
            switch (cmd)
            {
            case LoadCommand.Load:
                Initialize();
                SetFavorites();
                var drive = GetDriveFromPath(Settings.Directory);
                if (drive != null)
                {
                    PathCache.Add(drive, Settings.Directory);
                }
                Drive = drive ?? GetDefaultDrive();
                break;

            case LoadCommand.Restore:
                var payload = cmdParam.Payload as BinaryContent;
                if (payload == null)
                {
                    return;
                }
                WorkHandler.Run(
                    () =>
                {
                    File.WriteAllBytes(payload.FilePath, payload.Content);
                    return(true);
                },
                    result =>
                {
                    if (success != null)
                    {
                        success.Invoke(this);
                    }
                },
                    exception =>
                {
                    if (error != null)
                    {
                        error.Invoke(this, exception);
                    }
                });
                break;
            }
        }
Example #10
0
 public void Recognize(FileSystemItem item, Action <int> success, Action <Exception> error)
 {
     ProgressMessage = Resx.OpeningProfile;
     this.NotifyProgressStarted();
     WorkHandler.Run(() => RecognizeFromProfile(item),
                     result =>
     {
         this.NotifyProgressFinished();
         if (success != null)
         {
             success.Invoke(result);
         }
     },
                     exception =>
     {
         this.NotifyProgressFinished();
         if (error != null)
         {
             error.Invoke(exception);
         }
     });
 }
        private void AsyncJob <T>(Func <T> work, Action <T> success, Action <Exception> error = null)
        {
            EventAggregator.GetEvent <AsyncJobStartedEvent>().Publish(new AsyncJobStartedEventArgs(this));
            var finished = false;

            WorkHandler.Run(
                () =>
            {
                Thread.Sleep(3000);
                return(true);
            },
                b =>
            {
                if (finished)
                {
                    return;
                }
                WindowManager.ShowMessage(Resx.ApplicationIsBusy, Resx.PleaseWait, NotificationMessageFlags.NonClosable);
            });
            WorkHandler.Run(work,
                            b =>
            {
                WindowManager.CloseMessage();
                finished = true;
                success.Invoke(b);
                EventAggregator.GetEvent <AsyncJobFinishedEvent>().Publish(new AsyncJobFinishedEventArgs(this));
            },
                            e =>
            {
                WindowManager.CloseMessage();
                finished = true;
                if (error != null)
                {
                    error.Invoke(e);
                }
                EventAggregator.GetEvent <AsyncJobFinishedEvent>().Publish(new AsyncJobFinishedEventArgs(this));
            });
        }
        public void InitializeTransfer(Queue <QueueItem> queue, FileOperation mode)
        {
            _queue = queue;
            _paneCache.Clear();
            _isPaused                    = false;
            _isAborted                   = false;
            _isContinued                 = false;
            _deleteAll                   = false;
            _skipAll                     = null;
            UserAction                   = mode;
            TransferAction               = mode == FileOperation.Copy ? GetCopyActionText() : Resx.ResourceManager.GetString(mode.ToString());
            _rememberedCopyAction        = CopyAction.CreateNew;
            _currentFileBytesTransferred = 0;
            CurrentFileProgress          = 0;
            FilesTransferred             = 0;
            FileCount                    = _queue.Count;
            BytesTransferred             = 0;
            TotalBytes                   = _queue.Where(item => item.FileSystemItem.Type == ItemType.File).Sum(item => item.FileSystemItem.Size ?? 0);
            Speed         = 0;
            ElapsedTime   = new TimeSpan(0);
            RemainingTime = new TimeSpan(0);

            WorkHandler.Run(BeforeTransferStart, BeforeTransferStartCallback);
        }
        private void CheckDatabaseCallback(bool databaseExisted, Action <SanityCheckResult> callback)
        {
            var result           = new SanityCheckResult();
            var frameworkMessage = CheckFrameworkVersion();

            if (frameworkMessage != null)
            {
                result.UserMessages = new List <NotifyUserMessageEventArgs> {
                    frameworkMessage
                }
            }
            ;
            WorkHandler.Run(RetryFailedUserReports);

            if (!databaseExisted)
            {
                result.DatabaseCreated = true;
                WorkHandler.Run(MigrateEsentToDatabase, cacheStore => MigrateEsentToDatabaseCallback(cacheStore, callback, result));
            }
            else
            {
                callback.Invoke(result);
            }
        }
        public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null)
        {
            base.LoadDataAsync(cmd, cmdParam, success, error);
            switch (cmd)
            {
            case LoadCommand.Load:
                WorkHandler.Run(
                    () =>
                {
                    Connection = (FtpConnectionItemViewModel)cmdParam.Payload;
                    return(Connect());
                },
                    result =>
                {
                    IsLoaded         = true;
                    ResumeCapability = result;
                    try
                    {
                        ConnectCallback();
                    }
                    catch (Exception ex)
                    {
                        if (error != null)
                        {
                            error.Invoke(this, new SomethingWentWrongException(Resx.IndetermineFtpConnectionError, ex));
                        }
                        CloseCommand.Execute();
                        return;
                    }
                    if (success != null)
                    {
                        success.Invoke(this);
                    }
                },
                    exception =>
                {
                    if (error != null)
                    {
                        error.Invoke(this, exception);
                    }
                });
                break;

            case LoadCommand.Restore:
                var payload = cmdParam.Payload as BinaryContent;
                if (payload == null)
                {
                    return;
                }
                WorkHandler.Run(
                    () =>
                {
                    //TODO: upload binary
                    //File.WriteAllBytes(payload.TempFilePath, payload.Content);
                    //FileManager.RestoreConnection();
                    //FileManager.UploadFile(payload.FilePath, payload.TempFilePath);
                    return(true);
                },
                    result =>
                {
                    if (success != null)
                    {
                        success.Invoke(this);
                    }
                },
                    exception =>
                {
                    CloseCommand.Execute();
                    if (error != null)
                    {
                        error.Invoke(this, exception);
                    }
                });
                break;
            }
        }
        private void ProcessQueueItem(CopyAction?action = null, string rename = null)
        {
            if (_queue.Count > 0)
            {
                var queueitem = _queue.Peek();
                var item      = queueitem.FileSystemItem;
                SourceFile = item.GetRelativePath(SourcePane.CurrentFolder.Path);

                if (queueitem.Confirmation)
                {
                    switch (queueitem.Operation)
                    {
                    case FileOperation.Delete:
                        if (!_deleteAll)
                        {
                            var payload = queueitem.Payload as FileSystemItem;
                            if (payload == null)
                            {
                                throw new Exception("payload cannot be null");
                            }
                            _elapsedTimeMeter.Stop();
                            var result = WindowManager.ShowDeleteConfirmationDialog(payload.Path);
                            _elapsedTimeMeter.Start();
                            switch (result)
                            {
                            case DeleteConfirmationResult.Delete:
                                //do nothing
                                break;

                            case DeleteConfirmationResult.DeleteAll:
                                _deleteAll = true;
                                break;

                            case DeleteConfirmationResult.Skip:
                                while (queueitem.FileSystemItem != payload)
                                {
                                    _queue.Dequeue();
                                    queueitem = _queue.Peek();
                                }
                                ProcessSuccess(new OperationResult(TransferResult.Skipped));
                                return;

                            case DeleteConfirmationResult.Cancel:
                                FinishTransfer();
                                return;
                            }
                        }
                        break;

                    default:
                        throw new NotSupportedException("Invalid operation: " + queueitem.Operation);
                    }
                }

                WorkHandler.Run(() =>
                {
                    switch (queueitem.Operation)
                    {
                    case FileOperation.Copy:
                        return(ExecuteCopy(queueitem, action ?? queueitem.CopyAction, rename));

                    case FileOperation.Delete:
                        return(ExecuteDelete(queueitem));

                    case FileOperation.Verify:
                        return(ExecuteVerification(queueitem));

                    default:
                        throw new NotSupportedException("Invalid transfer type: " + queueitem.Operation);
                    }
                }, ProcessSuccess, ProcessError);
                return;
            }
            FinishTransfer();
        }
        public void Check()
        {
            IsBusy          = true;
            ProgressMessage = Resx.GettingData + Strings.DotDotDot;
            IsIndetermine   = true;
            var missingFolders = new List <FileSystemItem>();
            var missingEntries = new Dictionary <FileSystemItem, IList <FileSystemItem> >();

            this.NotifyProgressStarted();

            WorkHandler.Run(() =>
            {
                var gameFolders = new List <FileSystemItem>();
                foreach (var drive in _parent.Drives)
                {
                    try
                    {
                        gameFolders.AddRange(_parent.GetList(drive.Path + "Content/0000000000000000"));
                    }
                    catch
                    {
                    }
                }

                var rows    = _parent.GetContentItems();
                _itemsCount = rows.Count();

                UIThread.Run(() => IsIndetermine = false);

                if (!rows.Any())
                {
                    return(Resx.FreestyleDatabaseIsEmpty);
                }

                foreach (var row in rows)
                {
                    var titleIdInt = Int32.Parse(row[FsdContentItemProperty.TitleId]);
                    if (titleIdInt != 0)
                    {
                        var titleId = titleIdInt.ToString("X");
                        gameFolders.RemoveAll(g => g.Name.Equals(titleId, StringComparison.InvariantCultureIgnoreCase));
                    }

                    var contentId = Int32.Parse(row[FsdContentItemProperty.Id]);
                    var title     = row[FsdContentItemProperty.Name];
                    UIThread.Run(() =>
                    {
                        ProgressMessage = Resx.Checking + Strings.ColonSpace + title;
                        NotifyPropertyChanged(PROGRESSVALUE);
                        NotifyPropertyChanged(PROGRESSVALUEDOUBLE);
                        NotifyPropertyChanged(PROGRESSDIALOGTITLE);
                    });
                    _itemsChecked++;
                    var scanPathId = Int32.Parse(row[FsdContentItemProperty.ScanPathId]);
                    if (!_parent.ScanFolders.ContainsKey(scanPathId))
                    {
                        //TODO: handle non-existent scan path
                        continue;
                    }
                    var f    = _parent.ScanFolders[scanPathId];
                    var path = string.Format("/{0}{1}", f.Drive, row[FsdContentItemProperty.Path].Replace("\\", "/"));
                    if (!_parent.FileExists(path))
                    {
                        missingFolders.Add(new FileSystemItem
                        {
                            Title     = title,
                            Path      = path,
                            Thumbnail = _parent.HttpGet(string.Format("assets/gameicon.png?contentid={0:X2}", contentId))
                        });
                    }
                }

                UIThread.Run(() => ProgressMessage = Resx.PleaseWait);

                foreach (var item in gameFolders)
                {
                    _parent.TitleRecognizer.RecognizeType(item);
                    if (item.TitleType != TitleType.Game)
                    {
                        continue;
                    }
                    if (!_parent.TitleRecognizer.MergeWithCachedEntry(item))
                    {
                        _parent.TitleRecognizer.RecognizeTitle(item);
                    }
                    var content = _parent.GetList(item.Path);
                    long sum    = 0;
                    content.ForEach(c =>
                    {
                        _parent.TitleRecognizer.RecognizeType(c);
                        var size = _parent.CalculateSize(c.Path);
                        c.Size   = size;
                        sum     += size;
                    });
                    item.Size = sum;
                    missingEntries.Add(item, content.OrderByDescending(c => c.Size).ToList());
                }

                return(null);
            },
                            result =>
            {
                IsBusy          = false;
                ProgressMessage = string.Empty;
                MissingFolders  = missingFolders.Select(m => new FileSystemItemViewModel(m)).ToObservableCollection();
                MissingEntries  = missingEntries.Select(m => new FileSystemItemViewModel(m.Key)
                {
                    Content = m.Value
                }).ToObservableCollection();
                if (!HasMissingFolders && !HasMissingEntries && string.IsNullOrEmpty(result))
                {
                    result = Resx.NoErrorsInFreestyleDatabase;
                }
                this.NotifyProgressFinished();
                EventAggregator.GetEvent <FreestyleDatabaseCheckedEvent>().Publish(new FreestyleDatabaseCheckedEventArgs(this, result));
            },
                            error =>
            {
                IsBusy          = false;
                ProgressMessage = string.Empty;
                this.NotifyProgressFinished();
                //TODO: swallow error and pop up a "something went wrong" text?
                WindowManager.ShowErrorMessage(error);
            });
        }
 public void CheckAsync(Action <SanityCheckResult> callback)
 {
     WorkHandler.Run(CheckDatabase, b => CheckDatabaseCallback(b, callback));
 }