Пример #1
0
        private async Task <Unit> OpenRedFileAsync(FileEntry file)
        {
            if (file != null)
            {
                _progressService.IsIndeterminate = true;
                try
                {
                    var fileViewModel = new RedDocumentViewModel(file.FileName);
                    await using (var stream = new MemoryStream())
                    {
                        file.Extract(stream);
                        fileViewModel.OpenStream(stream, null);
                    }

                    if (!DockedViews.Contains(fileViewModel))
                    {
                        DockedViews.Add(fileViewModel);
                    }

                    ActiveDocument = fileViewModel;
                    UpdateTitle();
                }
                catch (Exception e)
                {
                    _loggerService.Error(e.Message);
                }
                finally
                {
                    _progressService.IsIndeterminate = false;
                }
            }

            return(Unit.Default);
        }
Пример #2
0
        //private async Task RequestOpenFile(string fullPath)
        //{
        //    if (!File.Exists(fullPath))
        //    {
        //        _ = await Task.FromException<FileNotFoundException>(new FileNotFoundException(nameof(RequestOpenFile), fullPath));
        //    }
        //    // check if in
        //    await RequestFileOpen(fullPath);
        //}

        /// <summary>
        /// Open a file and return its content in a viewmodel.
        /// </summary>
        /// <returns></returns>
        private IDocumentViewModel Open(string fullPath, EWolvenKitFile type)
        {
            // Check if we have already loaded this file and return it if so
            var fileViewModel = OpenDocuments.FirstOrDefault(fm => fm.ContentId == fullPath);

            if (fileViewModel != null)
            {
                return(fileViewModel);
            }

            // open file
            switch (type)
            {
            case EWolvenKitFile.Cr2w:
                fileViewModel = new RedDocumentViewModel(fullPath);
                break;

            case EWolvenKitFile.Redscript:
                fileViewModel = new ScriptDocumentViewModel(fullPath);
                break;

            case EWolvenKitFile.Tweak:
                fileViewModel = new TweakDocumentViewModel(fullPath);
                break;

            default:
                break;
            }

            //var result = await fileViewModel.OpenFileAsync(fullPath);
            var result = fileViewModel.OpenFile(fullPath);


            if (result)
            {
                _loggerService.Success($"Opening File: {fullPath}");

                // TODO: this is not threadsafe
                //handler.Report(fileViewModel);

                //Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
                //{
                //    addfiledel(fileViewModel);
                //}), DispatcherPriority.ContextIdle);

                return(fileViewModel);
            }

            _loggerService.Warning($"Unable to open file: {fullPath}");
            return(null);
        }
Пример #3
0
        public void OpenFileFromHash(ulong hash)
        {
            if (hash != 0)
            {
                _progressService.IsIndeterminate = true;
                try
                {
                    var _archiveManager = Locator.Current.GetService <IArchiveManager>();
                    var file            = _archiveManager.Lookup(hash);
                    if (file.HasValue && file.Value is FileEntry fe)
                    {
                        var fileViewModel = new RedDocumentViewModel(fe.FileName);
                        using (var stream = new MemoryStream())
                        {
                            fe.Extract(stream);
                            fileViewModel.OpenStream(stream, null);
                        }
                        if (!DockedViews.Contains(fileViewModel))
                        {
                            DockedViews.Add(fileViewModel);
                        }

                        ActiveDocument = fileViewModel;
                        UpdateTitle();
                    }
                }
                catch (Exception e)
                {
                    _loggerService.Error(e.Message);
                }
                finally
                {
                    _progressService.IsIndeterminate = false;
                }
            }
        }