Пример #1
0
        public void DeleteFileCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;

            if (e.Parameter == null)
            {
                return;
            }

            try
            {
                DiskContent dc = e.Parameter as DiskContent;

                if (!dc.Exists)
                {
                    return;
                }
                else
                {
                    File.Delete(dc.FullName);
                }
            }
            catch (Exception Error)
            {
                Tracer.Error("MainWindow.DeleteFileCommandHandler", Error);
            }
        }
Пример #2
0
        //private void bw_DoWorkRefresh(object sender, DoWorkEventArgs e)
        //{
        //    Tracer.Verbose("ProjectService:bw_DoWorkRefresh", "START");

        //    try
        //    {
        //        CecilAssemblyParser parser = new CecilAssemblyParser((BackgroundWorker)sender, e);

        //        foreach (AssemblyType typ in ((ProjectEntity)e.Argument).Assemblies)
        //            parser.RefreshAssembly(typ);
        //    }
        //    catch (Exception err)
        //    {
        //        Tracer.Error("ProjectService.bw_DoWorkRefresh", err);
        //    }
        //    finally
        //    {
        //        Tracer.Verbose("ProjectService:bw_DoWorkRefresh", "END");

        //        //be sure progress is stoped
        //        EventDispatcher.Instance.RaiseStatus("", StatusEventType.StopProgress);
        //    }
        //}


        #endregion

        #region ----------------ADD/REMOVE ASSEMBLIES----------------

        /// <summary>
        /// Add an assembly from a given filename
        /// </summary>
        /// <param name="pathFile"></param>
        public void AddAssembly(string pathFile)
        {
            if (Current == null)
            {
                return;
            }

            DiskContent dc   = new DiskContent(pathFile);
            string      dest = Path.Combine(Current.SubFolderProfiled, dc.Name);

            File.Copy(pathFile, dest);

            EventDispatcher.Instance.RaiseStatus(Resources.CORE_PARSING_START, StatusEventType.StartProgress);

            //ask for a worker to parse the assembly
            AssemblyBackgroundWorkerParser parser = AssemblyParserFactory.GetBackgroundWorkerParser(eParserType.CecilParser);

            parser.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ParsingWorkCompleted);
            parser.Parse(dest);

            ////Init the background worker process
            //BackgroundWorker worker = new BackgroundWorker();
            //worker.DoWork += new DoWorkEventHandler(bw_DoWorkParse);
            //worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ParsingWorkCompleted);
            //worker.RunWorkerAsync(pathFile);
        }
Пример #3
0
        public static void Main111(string[] args)
        {
            const string drive = "X:";

            // label
            var driveInfo = new DriveInfo(drive);

            driveInfo.VolumeLabel = DiskContent.VolumeLabel;

            // long contiguous file
            using (var fc = File.Create(Path.Combine(drive, DiskContent.LongContiguousFileName)))
            {
                for (ulong offset = 0; offset < DiskContent.LongFileSize; offset += sizeof(ulong))
                {
                    var b = LittleEndian.GetBytes(DiskContent.GetLongContiguousFileNameOffsetValue(offset));
                    fc.Write(b, 0, b.Length);
                }
            }

            // long sparse files
            const uint chunks = 1u << 10;

            for (ulong offsetBase = 0; offsetBase < DiskContent.LongFileSize; offsetBase += chunks)
            {
                using (var fs1 = File.OpenWrite(Path.Combine(drive, DiskContent.LongSparseFile1Name)))
                    using (var fs2 = File.OpenWrite(Path.Combine(drive, DiskContent.LongSparseFile2Name)))
                    {
                        fs1.Seek(0, SeekOrigin.End);
                        fs2.Seek(0, SeekOrigin.End);
                        for (ulong subOffset = 0; subOffset < chunks; subOffset += sizeof(ulong))
                        {
                            var offset = offsetBase + subOffset;
                            var b1     = LittleEndian.GetBytes(DiskContent.GetLongSparseFile1NameOffsetValue(offset));
                            fs1.Write(b1, 0, b1.Length);
                            var b2 = LittleEndian.GetBytes(DiskContent.GetLongSparseFile2NameOffsetValue(offset));
                            fs2.Write(b2, 0, b2.Length);
                        }
                    }
            }

            // An empty folder
            Directory.CreateDirectory(Path.Combine(drive, DiskContent.EmptyRootFolderFileName));

            // A folder full of garbage
            var longDirectoryPath = Path.Combine(drive, DiskContent.LongFolderFileName);

            Directory.CreateDirectory(longDirectoryPath);
            for (int subFileIndex = 0; subFileIndex < DiskContent.LongFolderEntriesCount; subFileIndex++)
            {
                var path = Path.Combine(longDirectoryPath, Guid.NewGuid().ToString("N"));
                using (var t = File.CreateText(path))
                {
                    t.WriteLine(subFileIndex);
                }
            }
        }
Пример #4
0
        public void OpenDocument(DiskContent dc)
        {
            SupportedDocumentInfo info = SupportedDocuments.Find(p => p.Extension == dc.Extension);

            if (info != null)
            {
                IDocumentDataContext context = (IDocumentDataContext)Activator.CreateInstance(info.DocumentDataType);
                context.FullName = dc.FullName;
                GetDocument(info, context, true);
            }
        }
Пример #5
0
        public void DeleteCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;

            DiskContent dc = e.Parameter as DiskContent;

            if (dc.Delete())
            {
                this.treeViewTemplate.Items.Remove(this.treeViewTemplate.SelectedItem);
            }
        }
Пример #6
0
        private void treeViewTemplate_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem clickedItem = this.treeViewTemplate.FindItemUnderMouse(e) as TreeViewItem;

            if (clickedItem.Tag is DiskContent)
            {
                DiskContent dc = (DiskContent)clickedItem.Tag;

                if (dc.IsFile)
                {
                    ApplicationCommands.Open.Execute(dc, Application.Current.MainWindow);
                }
            }
        }
Пример #7
0
        public void OpenCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;
            DiskContent dc = e.Parameter as DiskContent;

            if (!dc.Exists)
            {
                return;
            }
            else
            {
                DocumentFactory.Instance.OpenDocument(typeof(TemplateDocument), new TemplateDocumentDataContext()
                {
                    FullName = dc.FullName
                });
            }
        }
Пример #8
0
 public void ReadFile()
 {
     using (var testEnvironment = StreamTestEnvironment.FromExistingVhdx())
         using (var filesystem = new ExFatEntryFilesystem(testEnvironment.PartitionStream))
         {
             var file = filesystem.FindChild(filesystem.RootDirectory, DiskContent.LongContiguousFileName);
             var vb   = new byte[sizeof(ulong)];
             using (var stream = filesystem.OpenFile(file, FileAccess.Read))
             {
                 for (ulong offset = 0; offset < DiskContent.LongFileSize; offset += 8)
                 {
                     stream.Read(vb, 0, vb.Length);
                     var v = LittleEndian.ToUInt64(vb);
                     Assert.AreEqual(v, DiskContent.GetLongContiguousFileNameOffsetValue(offset));
                 }
             }
         }
 }
Пример #9
0
 public void TruncateFileTest()
 {
     using (var testEnvironment = StreamTestEnvironment.FromExistingVhdx(true))
     {
         using (var filesystem = new ExFatEntryFilesystem(testEnvironment.PartitionStream))
         {
             var f = filesystem.FindChild(filesystem.RootDirectory, DiskContent.LongContiguousFileName);
             using (var s = filesystem.OpenFile(f, FileAccess.ReadWrite))
             {
                 s.SetLength(16);
                 s.Seek(0, SeekOrigin.Begin);
                 var b = new byte[8];
                 Assert.AreEqual(8, s.Read(b, 0, b.Length));
                 Assert.AreEqual(DiskContent.GetLongContiguousFileNameOffsetValue(0), LittleEndian.ToUInt64(b));
                 Assert.AreEqual(8, s.Read(b, 0, b.Length));
                 Assert.AreEqual(DiskContent.GetLongContiguousFileNameOffsetValue(8), LittleEndian.ToUInt64(b));
                 Assert.AreEqual(0, s.Read(b, 0, b.Length));
             }
         }
     }
 }
Пример #10
0
        void treeViewTemplate_OnItemNeedPopulate(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.Wait;

                TreeViewItem openedItem = (TreeViewItem)e.OriginalSource;

                DiskContent dc = openedItem.Tag as DiskContent;
                if (dc.IsFolder)
                {
                    ParseFolder(openedItem, dc.FullName);
                }
            }
            catch (Exception all)
            {
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Пример #11
0
        /// <summary>
        /// Open compliant and supported file as document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OpenCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;

            if (e.Parameter == null)              //from backstage, have to display the open dialog
            {
                try
                {
                    using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog())
                    {
                        dlg.Filter = DocumentFactory.Instance.GetAllSupportedFilter();

                        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            DiskContent dc = new DiskContent(dlg.FileName);
                            DocumentFactory.Instance.OpenDocument(dc);
                        }
                    }
                }
                catch (Exception all)
                {
                    Tracer.Error("AssemblyExplorer.BtnAddAssembly_Click", all);
                }
            }
            else              //file as parameter from template, project...
            {
                DiskContent dc = e.Parameter as DiskContent;

                if (!dc.Exists)
                {
                    return;
                }
                else
                {
                    DocumentFactory.Instance.OpenDocument(dc);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/folders/folder_closed.png")));
            }

            DiskContent container = value as DiskContent;

            if (container.IsFolder)
            {
                if (parameter.ToString() == "Closed")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/folders/folder_closed.png")));
                }
                else
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/folders/folder_opened.png")));
                }
            }

            return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/plugin.png")));
        }
Пример #13
0
        private void AddFile(TreeViewItem parent, string path)
        {
            DiskContent dc = new DiskContent(path);

            this.treeViewTemplate.AddItem(parent, dc.Name, dc, false);
        }
Пример #14
0
        private void AddFolder(TreeViewItem parent, string path)
        {
            DiskContent dc = new DiskContent(path, true);

            this.treeViewTemplate.AddItem(parent, dc.Name, dc);
        }