Exemplo n.º 1
0
        public void AddUnit(ITreeUnit parentUnit, ITreeUnit nUnit)
        {
            if (nUnit == null)
            {
                throw new ArgumentNullException($"{nameof(nUnit)}");
            }

            ThreadInvoker.UIInvoke(() => {
                if (parentUnit == null)
                {
                    VM.AddUnit(nUnit);
                }
                else
                {
                    parentUnit.Children.Add(nUnit);
                }
            });

            try {
                CommonEventHelper.GetEvent <TreeUnitAddedEvent>().Publish((nUnit, this));
                CommonEventHelper.PublishEventToHandlers((nUnit, this as ITreeService), _treeUnitAddedEventHandlers);
            }
            catch (Exception ex) {
                LoggerService.WriteCallerLine(ex.Message);
            }
        }
 public void PopupDevices(List <Device> devices)
 {
     ThreadInvoker.UIInvoke(() => {
         Devices.Clear();
         try {
             if (devices == null || devices.Count == 0)
             {
                 TipWord = ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("PleaseConnectToPhone");
                 return;
             }
             devices.ForEach(p => {
                 var newDev = new AdbDeviceModel {
                     Name = p.Disply, Device = p
                 };
                 Devices.Add(newDev);
             });
             SelectedDevice = Devices[0];
             TipWord        = ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("ChooseDeviceDetected");
         }
         catch (Exception ex) {
             Logger.WriteLine($"{nameof(DeviceSelectorViewModel)}->{ nameof(PopupDevices)}:{ ex.Message}");
             MsgBoxService.ShowError($"{nameof(PopupDevices)}:{ex.Message}");
         }
     });
 }
        private void RefreshFilesCount(IFolderBrowserDataContext dataContext)
        {
            if (dataContext == null)
            {
                return;
            }
            var vm = dataContext.FolderBrowserViewModel;

            if (vm == null)
            {
                return;
            }

            long fileCount    = 0;
            long regFileCount = 0;
            long dirCount     = 0;

            try {
                foreach (var file in vm.FileRows)
                {
                    if (file.File is IRegularFile)
                    {
                        regFileCount++;
                    }
                    else if (file.File is IDirectory)
                    {
                        dirCount++;
                    }
                    fileCount++;
                }

                ThreadInvoker.UIInvoke(() => {
                    var fileCountItem    = StatusBarService.GetOrCreateStatusBarTextItem(Constants.StatusBarItemText_FileCount, GridChildLength.Auto, 5);
                    var regFileCountItem = StatusBarService.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_RegFileCount, GridChildLength.Auto, 6);
                    var dirCountItem     = StatusBarService.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_DirectoryCount, GridChildLength.Auto, 7);

                    fileCountItem.Text    = $"{LanguageService.FindResourceString(Constants.StatusBarItemText_FileCount)} {fileCount}";
                    regFileCountItem.Text = $"{LanguageService.FindResourceString(Constants.StatusBarItemText_RegFileCount)} {regFileCount}";
                    dirCountItem.Text     = $"{LanguageService.FindResourceString(Constants.StatusBarItemText_DirectoryCount)} {dirCount}";
                });
            }
            catch (Exception ex) {
                LoggerService.WriteCallerLine(ex.Message);
            }
        }
Exemplo n.º 4
0
 public void Handle(IHexDataContext hexContext)
 {
     ThreadInvoker.BackInvoke(() => {
         var cmi  = CommandItemFactory.CreateNew(null);
         cmi.Name = LanguageService.FindResourceString(Constants.ContextCommandName_EncodingSelect);
         foreach (var encoding in _bytesToCharEncodings)
         {
             cmi.AddChild(CreateEncodingCommand(hexContext, encoding));
         }
         ThreadInvoker.UIInvoke(() => {
             hexContext.AddContextCommand(cmi);
             if (_bytesToCharEncodings.Length != 0)
             {
                 hexContext.BytesToCharEncoding = _bytesToCharEncodings[0];
             }
         });
     });
 }
Exemplo n.º 5
0
        /// <summary>
        /// 添加取证信息节点;
        /// </summary>
        /// <param name="cFile"></param>
        public void AddForensicUnit(ICaseEvidence cFile)
        {
            ITreeUnit fUnit       = null;
            var       caseService = ServiceProvider.Current.GetInstance <ICaseService>();

            if (caseService == null)
            {
                LoggerService.Current?.WriteCallerLine($"{nameof(caseService)} can't be null!");
            }

            ThreadInvoker.UIInvoke(() => {
                var tUnit = GetCaseFileUnit(cFile);
                if (tUnit != null)
                {
                    fUnit       = TreeUnitFactory.Current.CreateNew(Constants.ForensicInfoUnit);
                    fUnit.Label = FindResourceString("ForensicInfo");
                    tUnit.Children.Add(fUnit);
                }
            });
        }
Exemplo n.º 6
0
        //初始化核心;
        private void InitilizeCore()
        {
            IsLoading = true;

            ThreadInvoker.BackInvoke(() => {
                try {
                    _comObject = ComObject.Current;
                }
                catch (Exception ex) {
                    LoggerService.WriteCallerLine(ex.Message);
                    return;
                }

                var units = GetUnitsFromObject();

                ThreadInvoker.UIInvoke(() => {
                    DriveUnits.AddRange(units);
                });
                IsLoading = false;
            });
        }
        /// <summary>
        /// 递归保存目录;
        /// </summary>
        /// <param name="dir">目录本体</param>
        /// <param name="drPath">目标路径</param>
        /// <param name="saveFileFunc">文件保存通知进度委托</param>
        /// <param name="isCancel">动作是否取消委托</param>
        private static void TraverseSaveDirectory(IDirectory dir, string drPath,
                                                  Action <IRegularFile, string, string> saveFileFunc, Func <bool> isCancel = null)
        {
            if (dir.Children != null)
            {
                foreach (var p in dir.Children)
                {
                    if (isCancel?.Invoke() == true)
                    {
                        return;
                    }

                    if (p is IDirectory direct)
                    {
                        if (!SysIO.Directory.Exists($"{drPath}/{dir.Name}"))
                        {
                            try {
                                SysIO.Directory.CreateDirectory($"{drPath}/{dir.Name}");
                            }
                            catch (Exception ex) {
                                LoggerService.WriteCallerLine($" Creating Directory:{ex.Message}");
                                ThreadInvoker.UIInvoke(() => {
                                    MsgBoxService.ShowError($"{LanguageService.FindResourceString("FailedToCreateDirectory")}" +
                                                            $"{drPath}/{dir.Name}:{ex.Message}");
                                });
                            }
                        }
                        if (!direct.IsBack && !direct.IsLocalBackUp && direct.Name != ".." && direct.Name != ".")
                        {
                            TraverseSaveDirectory(direct, $"{drPath}/{dir.Name}", saveFileFunc, isCancel);
                        }
                    }
                    else if (p is IRegularFile regFile)
                    {
                        saveFileFunc(regFile, $"{drPath}/{dir.Name}", p.Name);
                    }
                }
            }
        }
        private static void RecoverFiles(IEnumerable <IFile> files)
        {
            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            long readSize  = 0;
            long totalSize = 0;

            try {
                #region 统计总大小;
                foreach (var file in files)
                {
                    if (file is IDirectory direc)
                    {
                        if (!direc.IsBack && !direc.IsLocalBackUp)
                        {
                            totalSize += direc.GetSubSize();
                        }
                    }
                    else if (file is IRegularFile)
                    {
                        totalSize += file.Size;
                    }
                }
                #endregion
            }
            catch (Exception ex) {
                LoggerService.WriteCallerLine($"Computing Size:{ex.Message}");
                MsgBoxService.ShowError($"{LanguageService.FindResourceString("FaileToToComputeTotalSize")}:{ex.Message}");
                return;
            }

            var proDialog = DialogService.Current.CreateLoadingDialog();
            proDialog.WindowTitle = $"{LanguageService.FindResourceString("FilesBeingCopied")}";

            void saveFileFunc(IRegularFile rFile, string drPath, string fileName)
            {
                FileStream fs = null;

                try {
                    fs = System.IO.File.Create($"{drPath}/{fileName ?? rFile.Name}");
                    int read;
                    using (var mulS = rFile.GetInputStream()) {
                        if (mulS == null)
                        {
                            return;
                        }
                        var buffer = new byte[10485760];
                        mulS.Position = 0;
                        while ((read = mulS.Read(buffer, 0, buffer.Length)) != 0 &&
                               !proDialog.CancellationPending)
                        {
                            fs.Write(buffer, 0, read);
                            readSize += read;
                            var pro = (int)(readSize * 100 / (totalSize != 0 ? totalSize : 4096));
                            proDialog.ReportProgress(pro <= 100 ? pro : 100, null,
                                                     $"{LanguageService.FindResourceString("CurExtractingFile")}:{fileName}");
                        }
                    }
                }
                catch (Exception ex) {
                    LoggerService.WriteCallerLine(ex.Message);
                    ThreadInvoker.UIInvoke(() => {
                        MsgBoxService.ShowError($"{LanguageService.FindResourceString("FailedToExtractFile")}:{ex.Message}");
                    });
                }
                finally {
                    fs?.Close();
                }
            }

            if (files.Count() == 1 && files.First() is IRegularFile regFile)
            {
                var saveFileName = DialogService.Current.GetSaveFilePath(regFile.Name);
                if (string.IsNullOrEmpty(saveFileName))
                {
                    return;
                }

                var fullPath = saveFileName;
                var drPath   = fullPath.Substring(0, fullPath.LastIndexOf("\\"));
                var fileName = fullPath.Substring(fullPath.LastIndexOf("\\") + 1);
                proDialog.DoWork += (sender, e) => {
                    if (!System.IO.Directory.Exists(drPath))
                    {
                        SysIO.Directory.CreateDirectory(drPath);
                    }
                    saveFileFunc(regFile, drPath, fileName);
                };

                proDialog.RunWorkerCompleted += (sender, e) => {
                    if (!e.Cancelled)
                    {
                        Process.Start("explorer.exe", SysIO.Path.GetFullPath(drPath));
                    }
                };

                proDialog.ShowDialog(ViewProvider.GetView(Contracts.Shell.Constants.ShellView));
            }
            else
            {
                var drPath = DialogService.Current.OpenDirect();
                if (string.IsNullOrEmpty(drPath))
                {
                    return;
                }


                proDialog.DoWork += (sender, e) => {
                    if (!System.IO.Directory.Exists(drPath))
                    {
                        System.IO.Directory.CreateDirectory(drPath);
                    }
                    foreach (var file in files)
                    {
                        if (file is IDirectory direct)
                        {
                            TraverseSaveDirectory(direct, drPath, saveFileFunc, () => proDialog.CancellationPending);
                        }
                        else if (file is IRegularFile regFile2)
                        {
                            saveFileFunc(regFile2, drPath, file.Name);
                        }
                        if (proDialog.CancellationPending)
                        {
                            break;
                        }
                    }
                };
                proDialog.RunWorkerCompleted += (sender, e) => {
                    if (!e.Cancelled)
                    {
                        Process.Start("explorer.exe", SysIO.Path.GetFullPath(drPath));
                    }
                };
                proDialog.ShowDialog();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 加载案件;
        /// </summary>
        /// <param name="cFile"></param>
        public void LoadCase(ICase cs)
        {
            if (cs == null)
            {
                throw new ArgumentNullException(nameof(cs));
            }

            //关闭尚未关闭的案件;
            if (CurrentCase != null)
            {
                CloseCurrentCase();
            }

            //若当前案件仍不为空,则关闭案件未完成,需中断加载案件;
            if (CurrentCase != null)
            {
                return;
            }

            //发布案件加载中事件;
            CommonEventHelper.GetEvent <CaseLoadingEvent>().Publish(cs);
            CurrentCase = cs;

            //从文档中加载证据项;
            var msg = ServiceProvider.Current.GetInstance <IDialogService>()?.CreateDoubleLoadingDialog();

            if (msg == null)
            {
                LoggerService.Current?.WriteCallerLine($"{nameof(IDialogService)} can't be null.");
                return;
            }

            msg.Title = LanguageService.Current?.FindResourceString(LoadingCase);

            msg.DoWork += delegate {
                //构建进度回调器;
                var reporter = ProgessReporterFactory.CreateNew();
                reporter.ProgressReported += (sender, e) => {
                    msg.ReportProgress(e.totalPer, e.detailPer, e.desc, e.detail);
                };

                //证据项元素;
                var evidenceElems = cs.XDoc.Root.Elements(Contracts.Casing.Constants.CaseEvidenceRootElemName);

                foreach (var elem in evidenceElems)
                {
                    try {
                        var csEvidence = LoadCaseEvidenceFromXElem(elem);

                        //加载证据项;
                        CurrentCase.LoadCaseEvidence(csEvidence, reporter);
                    }
                    catch (Exception ex) {
                        Logger.WriteCallerLine(ex.Message);
                        ThreadInvoker.UIInvoke(() => {
                            MsgBoxService.ShowError(ex.Message);
                        });
                    }
                }

                //发布加载案件完成的事件;
                CommonEventHelper.GetEvent <CaseLoadedEvent>().Publish();
                CommonEventHelper.PublishEventToHandlers <ICaseLoadedEventHandler>();
            };


            msg.ShowDialog();
        }