Exemplo n.º 1
0
 private TreeGridItemCollection GetTree(List<FullStory> stories)
 {
     TreeGridItemCollection data = new TreeGridItemCollection();
     foreach (FullStory story in stories)
     {
         TreeGridItem tgiParent = new TreeGridItem() { Values = new object[] { WebUtility.HtmlDecode(story.title) } };
         string all5 = string.Empty;
         foreach (string s in story.GetTopNWords(5))
         {
             all5 += s + " ";
         }
         tgiParent.Children.Add(new TreeGridItem() { Values = new object[] { WebUtility.HtmlDecode(all5) } });
         data.Add(tgiParent);
         foreach (children child in story.children)
         {
             TreeGridItem tgi = GetCommentTree(child);
             if (tgi.Tag != "empty")
             {
                 tgiParent.Children.Add(tgi);
             }
         }
     }
     return data;
 }
Exemplo n.º 2
0
        void InitializeComponent()
        {
            //exception handling

            var sf = s.UIScalingFactor;

            Application.Instance.UnhandledException += (sender, e) =>
            {
                new DWSIM.UI.Desktop.Editors.UnhandledExceptionView((Exception)e.ExceptionObject).ShowModalAsync();
            };

            Title = "DWSIMLauncher".Localize();

            switch (GlobalSettings.Settings.RunningPlatform())
            {
            case GlobalSettings.Settings.Platform.Windows:
                ClientSize = new Size((int)(690 * sf), (int)(420 * sf));
                break;

            case GlobalSettings.Settings.Platform.Linux:
                ClientSize = new Size((int)(690 * sf), (int)(370 * sf));
                break;

            case GlobalSettings.Settings.Platform.Mac:
                ClientSize = new Size((int)(690 * sf), (int)(350 * sf));
                break;
            }

            Icon = Eto.Drawing.Icon.FromResource(imgprefix + "DWSIM_ico.ico");

            var bgcolor = new Color(0.051f, 0.447f, 0.651f);

            if (s.DarkMode)
            {
                bgcolor = SystemColors.ControlBackground;
            }

            Eto.Style.Add <Button>("main", button =>
            {
                button.BackgroundColor = bgcolor;
                button.Font            = new Font(FontFamilies.Sans, 12f, FontStyle.None);
                button.TextColor       = Colors.White;
                button.ImagePosition   = ButtonImagePosition.Left;
                button.Width           = (int)(sf * 250);
                button.Height          = (int)(sf * 50);
            });

            Eto.Style.Add <Button>("donate", button =>
            {
                button.BackgroundColor = !s.DarkMode ? Colors.LightYellow : SystemColors.ControlBackground;
                button.Font            = new Font(FontFamilies.Sans, 12f, FontStyle.None);
                button.TextColor       = !s.DarkMode ? bgcolor : Colors.White;
                button.ImagePosition   = ButtonImagePosition.Left;
                button.Width           = (int)(sf * 250);
                button.Height          = (int)(sf * 50);
            });

            var btn1 = new Button()
            {
                Style = "main", Text = "OpenSavedFile".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "OpenFolder_100px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn2 = new Button()
            {
                Style = "main", Text = "NewSimulation".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "icons8-workflow.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn3 = new Button()
            {
                Style = "main", Text = "NewCompound".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "Peptide_100px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn4 = new Button()
            {
                Style = "main", Text = "NewDataRegression".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "AreaChart_100px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn6 = new Button()
            {
                Style = "main", Text = "User Guide".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "Help_100px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn7 = new Button()
            {
                Style = "main", Text = "About".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "Info_100px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn8 = new Button()
            {
                Style = "donate", Text = "Become a Patron", Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "icons8-patreon.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };
            var btn9 = new Button()
            {
                Style = "main", Text = "Preferences".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "ReportCard_96px.png"), (int)(sf * 40), (int)(sf * 40), ImageInterpolation.Default)
            };

            btn9.Click += (sender, e) =>
            {
                new Forms.Forms.GeneralSettings().GetForm().Show();
            };

            btn6.Click += (sender, e) =>
            {
                var basepath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                Process.Start(basepath + Path.DirectorySeparatorChar + "docs" + Path.DirectorySeparatorChar + "user_guide.pdf");
            };

            btn1.Click += (sender, e) =>
            {
                var dialog = new OpenFileDialog();
                dialog.Title = "Open File".Localize();
                dialog.Filters.Add(new FileFilter("XML Simulation File".Localize(), new[] { ".dwxml", ".dwxmz" }));
                dialog.Filters.Add(new FileFilter("Mobile XML Simulation File (Android/iOS)", new[] { ".xml" }));
                dialog.MultiSelect        = false;
                dialog.CurrentFilterIndex = 0;
                if (dialog.ShowDialog(this) == DialogResult.Ok)
                {
                    LoadSimulation(dialog.FileName);
                }
            };

            btn2.Click += (sender, e) =>
            {
                var form = new Forms.Flowsheet();
                AddUserCompounds(form.FlowsheetObject);
                OpenForms   += 1;
                form.Closed += (sender2, e2) =>
                {
                    OpenForms -= 1;
                };
                form.newsim = true;
                form.Show();
            };

            btn7.Click += (sender, e) => new AboutBox().Show();
            btn8.Click += (sender, e) => Process.Start("https://patreon.com/dwsim");

            var stack = new StackLayout {
                Orientation = Orientation.Vertical, Spacing = 5
            };

            stack.Items.Add(btn1);
            stack.Items.Add(btn2);
            stack.Items.Add(btn9);
            stack.Items.Add(btn6);
            stack.Items.Add(btn7);
            stack.Items.Add(btn8);

            var tableright = new TableLayout();

            tableright.Padding = new Padding(5, 5, 5, 5);
            tableright.Spacing = new Size(10, 10);

            MostRecentList = new TreeGridView {
                Height = (int)(sf * 330)
            };
            SampleList = new ListBox {
                BackgroundColor = bgcolor, Height = (int)(sf * 330)
            };
            FoldersList = new ListBox {
                BackgroundColor = bgcolor, Height = (int)(sf * 330)
            };
            FOSSEEList = new ListBox {
                BackgroundColor = bgcolor, Height = (int)(sf * 330)
            };

            if (Application.Instance.Platform.IsGtk &&
                GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
            {
                SampleList.TextColor  = bgcolor;
                FoldersList.TextColor = bgcolor;
                FOSSEEList.TextColor  = bgcolor;
            }
            else if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
            {
                SampleList.BackgroundColor  = SystemColors.ControlBackground;
                FoldersList.BackgroundColor = SystemColors.ControlBackground;
                FOSSEEList.BackgroundColor  = SystemColors.ControlBackground;
                SampleList.TextColor        = SystemColors.ControlText;
                FoldersList.TextColor       = SystemColors.ControlText;
                FOSSEEList.TextColor        = SystemColors.ControlText;
            }
            else
            {
                SampleList.TextColor  = Colors.White;
                FoldersList.TextColor = Colors.White;
                FOSSEEList.TextColor  = Colors.White;
            }

            MostRecentList.AllowMultipleSelection = false;
            MostRecentList.ShowHeader             = true;
            MostRecentList.Columns.Clear();
            MostRecentList.Columns.Add(new GridColumn {
                DataCell = new ImageViewCell(0)
                {
                    ImageInterpolation = ImageInterpolation.High
                }
            });
            MostRecentList.Columns.Add(new GridColumn {
                DataCell = new TextBoxCell(1), HeaderText = "Name", Sortable = true
            });
            MostRecentList.Columns.Add(new GridColumn {
                DataCell = new TextBoxCell(2), HeaderText = "Date", Sortable = true
            });
            MostRecentList.Columns.Add(new GridColumn {
                DataCell = new TextBoxCell(3), HeaderText = "DWSIM Version", Sortable = true
            });
            MostRecentList.Columns.Add(new GridColumn {
                DataCell = new TextBoxCell(4), HeaderText = "Operating System", Sortable = true
            });

            var invertedlist = new List <string>(GlobalSettings.Settings.MostRecentFiles);

            invertedlist.Reverse();

            var tgc = new TreeGridItemCollection();

            foreach (var item in invertedlist)
            {
                if (File.Exists(item))
                {
                    var li   = new TreeGridItem();
                    var data = new Dictionary <string, string>();
                    if (Path.GetExtension(item).ToLower() == ".dwxmz")
                    {
                        data = SharedClasses.Utility.GetSimulationFileDetails(FlowsheetBase.FlowsheetBase.LoadZippedXMLDoc(item));
                    }
                    else
                    {
                        data = SharedClasses.Utility.GetSimulationFileDetails(XDocument.Load(item));
                    }
                    li.Tag = data;
                    data.Add("Path", item);
                    DateTime dt;
                    if (data.ContainsKey("SavedOn"))
                    {
                        dt = DateTime.Parse(data["SavedOn"]);
                    }
                    else
                    {
                        dt = File.GetLastWriteTime(item);
                    }
                    string dwsimver, osver;
                    if (data.ContainsKey("DWSIMVersion"))
                    {
                        dwsimver = data["DWSIMVersion"];
                    }
                    else
                    {
                        dwsimver = "N/A";
                    }
                    if (data.ContainsKey("OSInfo"))
                    {
                        osver = data["OSInfo"];
                    }
                    else
                    {
                        osver = "N/A";
                    }
                    li.Values = new object[] { new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "icons8-workflow.png")).WithSize(16, 16),
                                               System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Path.GetFileNameWithoutExtension(item)),
                                               dt, dwsimver, osver };
                    tgc.Add(li);
                }
            }

            tgc = new TreeGridItemCollection(tgc.OrderByDescending(x => ((DateTime)((TreeGridItem)x).Values[2]).Ticks));

            MostRecentList.DataStore = tgc;

            IEnumerable <string> samplist = new List <string>();

            try
            {
                samplist = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "samples"), "*.dwxm*");
            }
            catch
            { }

            foreach (var item in samplist)
            {
                if (File.Exists(item))
                {
                    SampleList.Items.Add(new ListItem {
                        Text = Path.GetFileNameWithoutExtension(item), Key = item
                    });
                }
            }

            foreach (String f in invertedlist)
            {
                if (Path.GetExtension(f).ToLower() != ".dwbcs")
                {
                    if (FoldersList.Items.Where((x) => x.Text == Path.GetDirectoryName(f)).Count() == 0)
                    {
                        if (Directory.Exists(Path.GetDirectoryName(f)))
                        {
                            FoldersList.Items.Add(new ListItem {
                                Text = Path.GetDirectoryName(f), Key = Path.GetDirectoryName(f)
                            });
                        }
                    }
                }
            }

            FOSSEEList.Items.Add(new ListItem {
                Text = "Downloading flowsheet list, please wait...", Key = ""
            });

            Dictionary <string, SharedClasses.FOSSEEFlowsheet> fslist = new Dictionary <string, SharedClasses.FOSSEEFlowsheet>();

            Task.Factory.StartNew(() =>
            {
                return(SharedClasses.FOSSEEFlowsheets.GetFOSSEEFlowsheets());
            }).ContinueWith((t) =>
            {
                Application.Instance.Invoke(() =>
                {
                    FOSSEEList.Items.Clear();
                    if (t.Exception != null)
                    {
                        FOSSEEList.Items.Add(new ListItem {
                            Text = "Error loading flowsheet list. Check your internet connection.", Key = ""
                        });
                    }
                    else
                    {
                        foreach (var item in t.Result)
                        {
                            fslist.Add(item.DownloadLink, item);
                            FOSSEEList.Items.Add(new ListItem {
                                Text = item.DisplayName, Key = item.DownloadLink
                            });
                        }
                    }
                });
            });

            FoldersList.SelectedIndexChanged += (sender, e) =>
            {
                if (FoldersList.SelectedIndex >= 0)
                {
                    var dialog = new OpenFileDialog();
                    dialog.Title     = "Open File".Localize();
                    dialog.Directory = new Uri(FoldersList.SelectedKey);
                    dialog.Filters.Add(new FileFilter("XML Simulation File".Localize(), new[] { ".dwxml", ".dwxmz" }));
                    dialog.MultiSelect        = false;
                    dialog.CurrentFilterIndex = 0;
                    if (dialog.ShowDialog(this) == DialogResult.Ok)
                    {
                        LoadSimulation(dialog.FileName);
                    }
                }
            };

            MostRecentList.SelectedItemChanged += (sender, e) =>
            {
                if (MostRecentList.SelectedItem != null)
                {
                    var si   = (TreeGridItem)MostRecentList.SelectedItem;
                    var data = (Dictionary <string, string>)si.Tag;
                    LoadSimulation(data["Path"]);
                    //MostRecentList.SelectedIndex = -1;
                }
                ;
            };

            SampleList.SelectedIndexChanged += (sender, e) =>
            {
                if (SampleList.SelectedIndex >= 0)
                {
                    LoadSimulation(SampleList.SelectedKey);
                    //MostRecentList.SelectedIndex = -1;
                }
                ;
            };

            FOSSEEList.SelectedIndexChanged += (sender, e) =>
            {
                if (FOSSEEList.SelectedIndex >= 0 && FOSSEEList.SelectedKey != "")
                {
                    var item = fslist[FOSSEEList.SelectedKey];
                    var sb   = new StringBuilder();
                    sb.AppendLine("Title: " + item.Title);
                    sb.AppendLine("Author: " + item.ProposerName);
                    sb.AppendLine("Institution: " + item.Institution);
                    sb.AppendLine();
                    sb.AppendLine("Click 'Yes' to download and open this flowsheet.");

                    if (MessageBox.Show(sb.ToString(), "Open FOSSEE Flowsheet", MessageBoxButtons.YesNo, MessageBoxType.Information, MessageBoxDefaultButton.Yes) == DialogResult.Yes)
                    {
                        var loadingdialog = new LoadingData();
                        loadingdialog.loadingtext.Text = "Please wait, downloading file...\n(" + FOSSEEList.SelectedKey + ")";
                        loadingdialog.Show();
                        var address = FOSSEEList.SelectedKey;
                        Task.Factory.StartNew(() =>
                        {
                            return(SharedClasses.FOSSEEFlowsheets.DownloadFlowsheet(address, (p) =>
                            {
                                Application.Instance.Invoke(() => loadingdialog.loadingtext.Text = "Please wait, downloading file... (" + p + "%)\n(" + address + ")");
                            }));
                        }).ContinueWith((t) =>
                        {
                            Application.Instance.Invoke(() => loadingdialog.Close());
                            if (t.Exception != null)
                            {
                                MessageBox.Show(t.Exception.Message, "Error downloading file", MessageBoxButtons.OK, MessageBoxType.Error, MessageBoxDefaultButton.OK);
                            }
                            else
                            {
                                Application.Instance.Invoke(() => LoadSimulation(SharedClasses.FOSSEEFlowsheets.LoadFlowsheet(t.Result)));
                            }
                        });
                        FOSSEEList.SelectedIndex = -1;
                    }
                }
                ;
            };

            var fosseecontainer = c.GetDefaultContainer();
            var l1  = c.CreateAndAddLabelRow3(fosseecontainer, "About the Project");
            var l2  = c.CreateAndAddDescriptionRow(fosseecontainer, "FOSSEE, IIT Bombay, invites chemical engineering students, faculty and practitioners to the flowsheeting project using DWSIM. We want you to convert existing flowsheets into DWSIM and get honoraria and certificates.");
            var bu1 = c.CreateAndAddButtonRow(fosseecontainer, "Submit a Flowsheet", null, (b1, e1) => Process.Start("https://dwsim.fossee.in/flowsheeting-project"));
            var bu2 = c.CreateAndAddButtonRow(fosseecontainer, "About FOSSEE", null, (b2, e2) => Process.Start("https://fossee.in/"));
            var l3  = c.CreateAndAddLabelRow3(fosseecontainer, "Completed Flowsheets");

            if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
            {
                fosseecontainer.BackgroundColor = SystemColors.ControlBackground;
            }
            else
            {
                fosseecontainer.BackgroundColor = bgcolor;
                l1.TextColor        = Colors.White;
                l2.TextColor        = Colors.White;
                l3.TextColor        = Colors.White;
                bu1.TextColor       = Colors.White;
                bu2.TextColor       = Colors.White;
                bu1.BackgroundColor = bgcolor;
                bu2.BackgroundColor = bgcolor;
            }
            fosseecontainer.Add(FOSSEEList);
            fosseecontainer.EndVertical();

            var tabview = new TabControl();
            var tab1    = new TabPage(MostRecentList)
            {
                Text = "Recent Files"
            };;
            var tab2 = new TabPage(SampleList)
            {
                Text = "Samples"
            };;
            var tab2a = new TabPage(fosseecontainer)
            {
                Text = "FOSSEE Flowsheets"
            };;
            var tab3 = new TabPage(FoldersList)
            {
                Text = "Recent Folders"
            };;

            tabview.Pages.Add(tab1);
            tabview.Pages.Add(tab2);
            tabview.Pages.Add(tab2a);
            tabview.Pages.Add(tab3);

            tableright.Rows.Add(new TableRow(tabview));

            var tl = new DynamicLayout();

            tl.Add(new TableRow(stack, tableright));

            TableContainer = new TableLayout
            {
                Padding = 10,
                Spacing = new Size(5, 5),
                Rows    = { new TableRow(tl) }
            };

            if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
            {
                TableContainer.BackgroundColor = SystemColors.ControlBackground;
            }
            else
            {
                TableContainer.BackgroundColor = bgcolor;
            }


            Content = TableContainer;

            var quitCommand = new Command {
                MenuText = "Quit".Localize(), Shortcut = Application.Instance.CommonModifier | Keys.Q
            };

            quitCommand.Executed += (sender, e) =>
            {
                try
                {
                    DWSIM.GlobalSettings.Settings.SaveSettings("dwsim_newui.ini");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error Saving Settings to File", MessageBoxButtons.OK, MessageBoxType.Error, MessageBoxDefaultButton.OK);
                }
                if (MessageBox.Show(this, "ConfirmAppExit".Localize(), "AppExit".Localize(), MessageBoxButtons.YesNo, MessageBoxType.Information, MessageBoxDefaultButton.No) == DialogResult.Yes)
                {
                    Application.Instance.Quit();
                }
            };

            var aboutCommand = new Command {
                MenuText = "About".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "information.png"))
            };

            aboutCommand.Executed += (sender, e) => new AboutBox().Show();

            var aitem1 = new ButtonMenuItem {
                Text = "Preferences".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "icons8-sorting_options.png"))
            };

            aitem1.Click += (sender, e) =>
            {
                new Forms.Forms.GeneralSettings().GetForm().Show();
            };

            var hitem1 = new ButtonMenuItem {
                Text = "User Guide".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "help_browser.png"))
            };

            hitem1.Click += (sender, e) =>
            {
                var basepath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                Process.Start(basepath + Path.DirectorySeparatorChar + "docs" + Path.DirectorySeparatorChar + "user_guide.pdf");
            };

            var hitem2 = new ButtonMenuItem {
                Text = "Support".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "help_browser.png"))
            };

            hitem2.Click += (sender, e) =>
            {
                Process.Start("http://dwsim.inforside.com.br/wiki/index.php?title=Support");
            };

            var hitem3 = new ButtonMenuItem {
                Text = "Report a Bug".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "help_browser.png"))
            };

            hitem3.Click += (sender, e) =>
            {
                Process.Start("https://sourceforge.net/p/dwsim/tickets/");
            };

            var hitem4 = new ButtonMenuItem {
                Text = "Go to DWSIM's Website".Localize(), Image = new Bitmap(Eto.Drawing.Bitmap.FromResource(imgprefix + "help_browser.png"))
            };

            hitem4.Click += (sender, e) =>
            {
                Process.Start("http://dwsim.inforside.com.br");
            };

            // create menu
            Menu = new MenuBar
            {
                ApplicationItems = { aitem1 },
                QuitItem         = quitCommand,
                HelpItems        = { hitem1, hitem4, hitem2, hitem3 },
                AboutItem        = aboutCommand
            };

            Shown += MainForm_Shown;

            Closing += MainForm_Closing;

            //Plugins

            LoadPlugins();
        }
Exemplo n.º 3
0
 private TreeGridItemCollection GetTree(Story story)
 {
     TreeGridItemCollection data = new TreeGridItemCollection();
     foreach (Comment comment in story.Comments)
     {
         TreeGridItem tgi = GetCommentTree(comment);
         if(tgi.Tag != "empty")
         {
             data.Add(tgi);
         }
     }
     return data;
 }
Exemplo n.º 4
0
        private TreeGridView GetLayout(TreeGridItemCollection selectableItems)
        {
            var isMacOS = Eto.Platform.Detect.IsMac;

            var featureSelect = new TreeGridView()
            {
                GridLines             = GridLines.Horizontal,
                AllowColumnReordering = true,
                RowHeight             = 30,
            };

            featureSelect.CellDoubleClick   += this.CellDoubleClickHandler;
            featureSelect.CellClick         += this.CellClickHandler;
            featureSelect.ColumnHeaderClick += this.HeaderClickHandler;
            featureSelect.CellFormatting    += _OnFormatCell;

            var titleColumn = new GridColumn()
            {
                HeaderText = TagTypeLabel,
                DataCell   = new TextBoxCell(0),
                Resizable  = false,
                Sortable   = false,
                AutoSize   = false,
                Width      = 220, // Don't autosize; hides the arrow buttons on macOS
            };

            featureSelect.Columns.Add(titleColumn);

            var checkColumn = new GridColumn()
            {
                HeaderText = SelectTagLabel,
                DataCell   = new CheckBoxCell(1),
                Width      = isMacOS ? 53 : 44, // 53 minimum macOS without ellipses
                Resizable  = false,
                Sortable   = false,
            };

            featureSelect.Columns.Add(checkColumn);

            var nodeColumn = new GridColumn()
            {
                HeaderText = "Nodes Count",
                DataCell   = new TextBoxCell(2),
                Resizable  = false,
                Sortable   = false,
                Width      = isMacOS ? 98 : 88,
            };

            featureSelect.Columns.Add(nodeColumn);

            var wayColumn = new GridColumn()
            {
                HeaderText = "Ways Count",
                DataCell   = new TextBoxCell(3),
                Resizable  = false,
                Sortable   = false,
                Width      = isMacOS ? 98 : 88,
            };

            featureSelect.Columns.Add(wayColumn);

            var keyValueColumn = new GridColumn()
            {
                HeaderText = TagKVLabel,
                DataCell   = new TextBoxCell(4),
                Resizable  = false,
                Sortable   = false,
                AutoSize   = false,
                Width      = isMacOS ? 130 : 130,
            };

            featureSelect.Columns.Add(keyValueColumn);

            var linkColumn = new GridColumn()
            {
                HeaderText = TagWikiLabel,
                DataCell   = new TextBoxCell(5),
                Resizable  = false,
                Sortable   = false,
                Width      = isMacOS ? 67 : 62, // 67 minimum macOS without ellipses
            };

            featureSelect.Columns.Add(linkColumn);

            var descriptionColumn = new GridColumn()
            {
                HeaderText = "Description",
                DataCell   = new TextBoxCell(6),
                Resizable  = false,
                Sortable   = false,
            };

            featureSelect.Columns.Add(descriptionColumn);

            featureSelect.DataStore = selectableItems;
            return(featureSelect);
        }
Exemplo n.º 5
0
 public TableStrip(TreeGridItemCollection selectionState)
 {
     this.viewForm = GetLayout(selectionState);
 }
        internal void LoadData(byte[]                   scsiInquiryData, Inquiry.SCSIInquiry?scsiInquiry,
                               Dictionary <byte, byte[]> scsiEvpdPages, Modes.DecodedMode?scsiMode,
                               PeripheralDeviceTypes scsiType, byte[]               scsiModeSense6,
                               byte[]                   scsiModeSense10,
                               byte[]                   mmcConfiguration)
        {
            inquiryData   = scsiInquiryData;
            inquiry       = scsiInquiry;
            evpdPages     = scsiEvpdPages;
            mode          = scsiMode;
            type          = scsiType;
            modeSense6    = scsiModeSense6;
            modeSense10   = scsiModeSense10;
            configuration = mmcConfiguration;

            if (inquiryData == null || !inquiry.HasValue)
            {
                return;
            }

            Visible             = true;
            txtScsiInquiry.Text = Inquiry.Prettify(inquiry);

            if (mode.HasValue)
            {
                tabScsiModeSense.Visible = true;

                TreeGridItemCollection modePagesList = new TreeGridItemCollection();

                treeModeSensePages.Columns.Add(new GridColumn {
                    HeaderText = "Page", DataCell = new TextBoxCell(0)
                });

                treeModeSensePages.AllowMultipleSelection = false;
                treeModeSensePages.ShowHeader             = false;
                treeModeSensePages.DataStore = modePagesList;

                modePagesList.Add(new TreeGridItem
                {
                    Values = new object[]
                    {
                        "Header", Modes.PrettifyModeHeader(mode.Value.Header, type)
                    }
                });

                foreach (Modes.ModePage page in mode.Value.Pages.OrderBy(t => t.Page).ThenBy(t => t.Subpage))
                {
                    string pageNumberText = page.Subpage == 0
                                                ? $"MODE {page.Page:X2}h"
                                                : $"MODE {page.Page:X2} Subpage {page.Subpage:X2}";
                    string decodedText;

                    switch (page.Page)
                    {
                    case 0x00:
                    {
                        if (type == PeripheralDeviceTypes.MultiMediaDevice && page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_00_SFF(page.PageResponse);
                        }
                        else
                        {
                            decodedText = "Undecoded";
                        }

                        break;
                    }

                    case 0x01:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                                  ? Modes.PrettifyModePage_01_MMC(page.PageResponse)
                                                  : Modes.PrettifyModePage_01(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x02:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_02(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x03:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_03(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x04:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_04(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x05:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_05(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x06:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_06(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x07:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                                  ? Modes.PrettifyModePage_07_MMC(page.PageResponse)
                                                  : Modes.PrettifyModePage_07(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x08:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_08(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x0A:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_0A(page.PageResponse);
                        }
                        else if (page.Subpage == 1)
                        {
                            decodedText = Modes.PrettifyModePage_0A_S01(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x0B:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_0B(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x0D:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_0D(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x0E:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_0E(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x0F:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_0F(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x10:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = type == PeripheralDeviceTypes.SequentialAccess
                                                  ? Modes.PrettifyModePage_10_SSC(page.PageResponse)
                                                  : Modes.PrettifyModePage_10(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x11:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_11(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x12:
                    case 0x13:
                    case 0x14:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_12_13_14(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x1A:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_1A(page.PageResponse);
                        }
                        else if (page.Subpage == 1)
                        {
                            decodedText = Modes.PrettifyModePage_1A_S01(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x1B:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_1B(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x1C:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                                  ? Modes.PrettifyModePage_1C_SFF(page.PageResponse)
                                                  : Modes.PrettifyModePage_1C(page.PageResponse);
                        }
                        else if (page.Subpage == 1)
                        {
                            decodedText = Modes.PrettifyModePage_1C_S01(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x1D:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_1D(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x21:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "CERTANCE")
                        {
                            decodedText = Modes.PrettifyCertanceModePage_21(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x22:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "CERTANCE")
                        {
                            decodedText = Modes.PrettifyCertanceModePage_22(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x24:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                        {
                            decodedText = Modes.PrettifyIBMModePage_24(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x2A:
                    {
                        if (page.Subpage == 0)
                        {
                            decodedText = Modes.PrettifyModePage_2A(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x2F:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                        {
                            decodedText = Modes.PrettifyIBMModePage_2F(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x30:
                    {
                        if (Modes.IsAppleModePage_30(page.PageResponse))
                        {
                            decodedText = "Drive identifies as Apple OEM drive";
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x3B:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                        {
                            decodedText = Modes.PrettifyHPModePage_3B(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x3C:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                        {
                            decodedText = Modes.PrettifyHPModePage_3C(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x3D:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                        {
                            decodedText = Modes.PrettifyIBMModePage_3D(page.PageResponse);
                        }
                        else if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                        {
                            decodedText = Modes.PrettifyHPModePage_3D(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    case 0x3E:
                    {
                        if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "FUJITSU")
                        {
                            decodedText = Modes.PrettifyFujitsuModePage_3E(page.PageResponse);
                        }
                        else if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                        {
                            decodedText = Modes.PrettifyHPModePage_3E(page.PageResponse);
                        }
                        else
                        {
                            goto default;
                        }

                        break;
                    }

                    default:
                    {
                        decodedText = "Undecoded";
                        break;
                    }
                    }

                    // TODO: Automatic error reporting
                    if (decodedText == null)
                    {
                        decodedText = "Error decoding page, please open an issue.";
                    }
                    modePagesList.Add(new TreeGridItem {
                        Values = new object[] { pageNumberText, decodedText }
                    });
                }
            }

            if (evpdPages != null)
            {
                tabScsiEvpd.Visible      = true;
                treeEvpdPages.ShowHeader = false;

                TreeGridItemCollection evpdPagesList = new TreeGridItemCollection();

                treeEvpdPages.Columns.Add(new GridColumn {
                    HeaderText = "Page", DataCell = new TextBoxCell(0)
                });

                treeEvpdPages.AllowMultipleSelection = false;
                treeEvpdPages.ShowHeader             = false;
                treeEvpdPages.DataStore = evpdPagesList;

                foreach (KeyValuePair <byte, byte[]> page in evpdPages.OrderBy(t => t.Key))
                {
                    string evpdPageTitle   = "";
                    string evpdDecodedPage = "";
                    if (page.Key >= 0x01 && page.Key <= 0x7F)
                    {
                        evpdPageTitle   = $"ASCII Page {page.Key:X2}h";
                        evpdDecodedPage = EVPD.DecodeASCIIPage(page.Value);
                    }
                    else if (page.Key == 0x80)
                    {
                        evpdPageTitle   = "Unit Serial Number";
                        evpdDecodedPage = EVPD.DecodePage80(page.Value);
                    }
                    else if (page.Key == 0x81)
                    {
                        evpdPageTitle   = "SCSI Implemented operating definitions";
                        evpdDecodedPage = EVPD.PrettifyPage_81(page.Value);
                    }
                    else if (page.Key == 0x82)
                    {
                        evpdPageTitle   = "ASCII implemented operating definitions";
                        evpdDecodedPage = EVPD.DecodePage82(page.Value);
                    }
                    else if (page.Key == 0x83)
                    {
                        evpdPageTitle   = "SCSI Device identification";
                        evpdDecodedPage = EVPD.PrettifyPage_83(page.Value);
                    }
                    else if (page.Key == 0x84)
                    {
                        evpdPageTitle   = "SCSI Software Interface Identifiers";
                        evpdDecodedPage = EVPD.PrettifyPage_84(page.Value);
                    }
                    else if (page.Key == 0x85)
                    {
                        evpdPageTitle   = "SCSI Management Network Addresses";
                        evpdDecodedPage = EVPD.PrettifyPage_85(page.Value);
                    }
                    else if (page.Key == 0x86)
                    {
                        evpdPageTitle   = "SCSI Extended INQUIRY Data";
                        evpdDecodedPage = EVPD.PrettifyPage_86(page.Value);
                    }
                    else if (page.Key == 0x89)
                    {
                        evpdPageTitle   = "SCSI to ATA Translation Layer Data";
                        evpdDecodedPage = EVPD.PrettifyPage_89(page.Value);
                    }
                    else if (page.Key == 0xB0)
                    {
                        evpdPageTitle   = "SCSI Sequential-access Device Capabilities";
                        evpdDecodedPage = EVPD.PrettifyPage_B0(page.Value);
                    }
                    else if (page.Key == 0xB1)
                    {
                        evpdPageTitle   = "Manufacturer-assigned Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB1(page.Value);
                    }
                    else if (page.Key == 0xB2)
                    {
                        evpdPageTitle   = "TapeAlert Supported Flags Bitmap";
                        evpdDecodedPage = $"0x{EVPD.DecodePageB2(page.Value):X16}";
                    }
                    else if (page.Key == 0xB3)
                    {
                        evpdPageTitle   = "Automation Device Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB3(page.Value);
                    }
                    else if (page.Key == 0xB4)
                    {
                        evpdPageTitle   = "Data Transfer Device Element Address";
                        evpdDecodedPage = EVPD.DecodePageB4(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "quantum")
                    {
                        evpdPageTitle   = "Quantum Firmware Build Information page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Quantum(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "seagate")
                    {
                        evpdPageTitle   = "Seagate Firmware Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Seagate(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_IBM(page.Value);
                    }
                    else if (page.Key == 0xC1 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Serial Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C1_IBM(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1) &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        evpdPageTitle   = "Certance Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_C1_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC2 || page.Key == 0xC3 || page.Key == 0xC4 || page.Key == 0xC5 ||
                              page.Key == 0xC6) &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        switch (page.Key)
                        {
                        case 0xC2:
                            evpdPageTitle = "Head Assembly Serial Number";
                            break;

                        case 0xC3:
                            evpdPageTitle = "Reel Motor 1 Serial Number";
                            break;

                        case 0xC4:
                            evpdPageTitle = "Reel Motor 2 Serial Number";
                            break;

                        case 0xC5:
                            evpdPageTitle = "Board Serial Number";
                            break;

                        case 0xC6:
                            evpdPageTitle = "Base Mechanical Serial Number";
                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C2_C3_C4_C5_C6_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1 || page.Key == 0xC2 || page.Key == 0xC3 ||
                              page.Key == 0xC4 || page.Key == 0xC5) && StringHandlers
                             .CToString(inquiry.Value.VendorIdentification)
                             .ToLowerInvariant().Trim() == "hp")
                    {
                        switch (page.Key)
                        {
                        case 0xC0:
                            evpdPageTitle = "HP Drive Firmware Revision Levels page:";
                            break;

                        case 0xC1:
                            evpdPageTitle = "HP Drive Hardware Revision Levels page:";
                            break;

                        case 0xC2:
                            evpdPageTitle = "HP Drive PCA Revision Levels page:";
                            break;

                        case 0xC3:
                            evpdPageTitle = "HP Drive Mechanism Revision Levels page:";
                            break;

                        case 0xC4:
                            evpdPageTitle = "HP Drive Head Assembly Revision Levels page:";
                            break;

                        case 0xC5:
                            evpdPageTitle = "HP Drive ACI Revision Levels page:";
                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C0_to_C5_HP(page.Value);
                    }
                    else if (page.Key == 0xDF &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        evpdPageTitle   = "Certance drive status page";
                        evpdDecodedPage = EVPD.PrettifyPage_DF_Certance(page.Value);
                    }
                    else
                    {
                        if (page.Key == 0x00)
                        {
                            continue;
                        }

                        evpdPageTitle   = $"Page {page.Key:X2}h";
                        evpdDecodedPage = "Undecoded";
                        DicConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}",
                                                  page.Key);
                    }

                    evpdPagesList.Add(new TreeGridItem
                    {
                        Values = new object[] { evpdPageTitle, evpdDecodedPage, page.Value }
                    });
                }
            }

            if (configuration != null)
            {
                tabMmcFeatures.Visible = true;

                TreeGridItemCollection featuresList = new TreeGridItemCollection();

                treeMmcFeatures.Columns.Add(new GridColumn {
                    HeaderText = "Feature", DataCell = new TextBoxCell(0)
                });

                treeMmcFeatures.AllowMultipleSelection = false;
                treeMmcFeatures.ShowHeader             = false;
                treeMmcFeatures.DataStore = featuresList;

                Features.SeparatedFeatures ftr = Features.Separate(configuration);

                DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes",
                                          ftr.DataLength);
                DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION current profile is {0:X4}h",
                                          ftr.CurrentProfile);
                if (ftr.Descriptors != null)
                {
                    foreach (Features.FeatureDescriptor desc in ftr.Descriptors)
                    {
                        string featureNumber = $"Feature {desc.Code:X4}h";
                        string featureDescription;
                        DicConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code);

                        switch (desc.Code)
                        {
                        case 0x0000:
                            featureDescription = Features.Prettify_0000(desc.Data);
                            break;

                        case 0x0001:
                            featureDescription = Features.Prettify_0001(desc.Data);
                            break;

                        case 0x0002:
                            featureDescription = Features.Prettify_0002(desc.Data);
                            break;

                        case 0x0003:
                            featureDescription = Features.Prettify_0003(desc.Data);
                            break;

                        case 0x0004:
                            featureDescription = Features.Prettify_0004(desc.Data);
                            break;

                        case 0x0010:
                            featureDescription = Features.Prettify_0010(desc.Data);
                            break;

                        case 0x001D:
                            featureDescription = Features.Prettify_001D(desc.Data);
                            break;

                        case 0x001E:
                            featureDescription = Features.Prettify_001E(desc.Data);
                            break;

                        case 0x001F:
                            featureDescription = Features.Prettify_001F(desc.Data);
                            break;

                        case 0x0020:
                            featureDescription = Features.Prettify_0020(desc.Data);
                            break;

                        case 0x0021:
                            featureDescription = Features.Prettify_0021(desc.Data);
                            break;

                        case 0x0022:
                            featureDescription = Features.Prettify_0022(desc.Data);
                            break;

                        case 0x0023:
                            featureDescription = Features.Prettify_0023(desc.Data);
                            break;

                        case 0x0024:
                            featureDescription = Features.Prettify_0024(desc.Data);
                            break;

                        case 0x0025:
                            featureDescription = Features.Prettify_0025(desc.Data);
                            break;

                        case 0x0026:
                            featureDescription = Features.Prettify_0026(desc.Data);
                            break;

                        case 0x0027:
                            featureDescription = Features.Prettify_0027(desc.Data);
                            break;

                        case 0x0028:
                            featureDescription = Features.Prettify_0028(desc.Data);
                            break;

                        case 0x0029:
                            featureDescription = Features.Prettify_0029(desc.Data);
                            break;

                        case 0x002A:
                            featureDescription = Features.Prettify_002A(desc.Data);
                            break;

                        case 0x002B:
                            featureDescription = Features.Prettify_002B(desc.Data);
                            break;

                        case 0x002C:
                            featureDescription = Features.Prettify_002C(desc.Data);
                            break;

                        case 0x002D:
                            featureDescription = Features.Prettify_002D(desc.Data);
                            break;

                        case 0x002E:
                            featureDescription = Features.Prettify_002E(desc.Data);
                            break;

                        case 0x002F:
                            featureDescription = Features.Prettify_002F(desc.Data);
                            break;

                        case 0x0030:
                            featureDescription = Features.Prettify_0030(desc.Data);
                            break;

                        case 0x0031:
                            featureDescription = Features.Prettify_0031(desc.Data);
                            break;

                        case 0x0032:
                            featureDescription = Features.Prettify_0032(desc.Data);
                            break;

                        case 0x0033:
                            featureDescription = Features.Prettify_0033(desc.Data);
                            break;

                        case 0x0035:
                            featureDescription = Features.Prettify_0035(desc.Data);
                            break;

                        case 0x0037:
                            featureDescription = Features.Prettify_0037(desc.Data);
                            break;

                        case 0x0038:
                            featureDescription = Features.Prettify_0038(desc.Data);
                            break;

                        case 0x003A:
                            featureDescription = Features.Prettify_003A(desc.Data);
                            break;

                        case 0x003B:
                            featureDescription = Features.Prettify_003B(desc.Data);
                            break;

                        case 0x0040:
                            featureDescription = Features.Prettify_0040(desc.Data);
                            break;

                        case 0x0041:
                            featureDescription = Features.Prettify_0041(desc.Data);
                            break;

                        case 0x0042:
                            featureDescription = Features.Prettify_0042(desc.Data);
                            break;

                        case 0x0050:
                            featureDescription = Features.Prettify_0050(desc.Data);
                            break;

                        case 0x0051:
                            featureDescription = Features.Prettify_0051(desc.Data);
                            break;

                        case 0x0080:
                            featureDescription = Features.Prettify_0080(desc.Data);
                            break;

                        case 0x0100:
                            featureDescription = Features.Prettify_0100(desc.Data);
                            break;

                        case 0x0101:
                            featureDescription = Features.Prettify_0101(desc.Data);
                            break;

                        case 0x0102:
                            featureDescription = Features.Prettify_0102(desc.Data);
                            break;

                        case 0x0103:
                            featureDescription = Features.Prettify_0103(desc.Data);
                            break;

                        case 0x0104:
                            featureDescription = Features.Prettify_0104(desc.Data);
                            break;

                        case 0x0105:
                            featureDescription = Features.Prettify_0105(desc.Data);
                            break;

                        case 0x0106:
                            featureDescription = Features.Prettify_0106(desc.Data);
                            break;

                        case 0x0107:
                            featureDescription = Features.Prettify_0107(desc.Data);
                            break;

                        case 0x0108:
                            featureDescription = Features.Prettify_0108(desc.Data);
                            break;

                        case 0x0109:
                            featureDescription = Features.Prettify_0109(desc.Data);
                            break;

                        case 0x010A:
                            featureDescription = Features.Prettify_010A(desc.Data);
                            break;

                        case 0x010B:
                            featureDescription = Features.Prettify_010B(desc.Data);
                            break;

                        case 0x010C:
                            featureDescription = Features.Prettify_010C(desc.Data);
                            break;

                        case 0x010D:
                            featureDescription = Features.Prettify_010D(desc.Data);
                            break;

                        case 0x010E:
                            featureDescription = Features.Prettify_010E(desc.Data);
                            break;

                        case 0x0110:
                            featureDescription = Features.Prettify_0110(desc.Data);
                            break;

                        case 0x0113:
                            featureDescription = Features.Prettify_0113(desc.Data);
                            break;

                        case 0x0142:
                            featureDescription = Features.Prettify_0142(desc.Data);
                            break;

                        default:
                            featureDescription = "Unknown feature";
                            break;
                        }

                        featuresList.Add(new TreeGridItem {
                            Values = new object[] { featureNumber, featureDescription }
                        });
                    }
                }
                else
                {
                    DicConsole.DebugWriteLine("Device-Info command",
                                              "GET CONFIGURATION returned no feature descriptors");
                }
            }

            Invalidate();
        }
Exemplo n.º 7
0
        void Finish()
        {
            stkOptions.Visible  = false;
            btnClose.Visible    = true;
            stkProgress.Visible = false;
            stkResults.Visible  = true;

            if (chkSeparatedTracks.Checked == true)
            {
                var entropyList = new TreeGridItemCollection();

                treeTrackEntropy.Columns.Add(new GridColumn
                {
                    HeaderText = "Track", DataCell = new TextBoxCell(0)
                });

                treeTrackEntropy.Columns.Add(new GridColumn
                {
                    HeaderText = "Entropy", DataCell = new TextBoxCell(1)
                });

                if (chkDuplicatedSectors.Checked == true)
                {
                    treeTrackEntropy.Columns.Add(new GridColumn
                    {
                        HeaderText = "Unique sectors", DataCell = new TextBoxCell(2)
                    });
                }

                treeTrackEntropy.AllowMultipleSelection = false;
                treeTrackEntropy.ShowHeader             = true;
                treeTrackEntropy.DataStore = entropyList;

                foreach (EntropyResults trackEntropy in tracksEntropy)
                {
                    entropyList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            trackEntropy.Track, trackEntropy.Entropy,
                            $"{trackEntropy.UniqueSectors} ({(double)trackEntropy.UniqueSectors / (double)trackEntropy.Sectors:P3})"
                        }
                    });
                }

                grpTrackEntropy.Visible = true;
            }

            if (chkWholeDisc.Checked != true)
            {
                return;
            }

            lblMediaEntropy.Text    = $"Entropy for disk is {entropy.Entropy:F4}.";
            lblMediaEntropy.Visible = true;

            if (entropy.UniqueSectors == null)
            {
                return;
            }

            lblMediaUniqueSectors.Text =
                $"Disk has {entropy.UniqueSectors} unique sectors ({(double)entropy.UniqueSectors / (double)entropy.Sectors:P3})";

            lblMediaUniqueSectors.Visible = true;
        }
Exemplo n.º 8
0
        public dlgStatistics()
        {
            XamlReader.Load(this);

            var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);

            if (ctx.Commands.Any())
            {
                if (ctx.Commands.Any(c => c.Name == "analyze"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "analyze" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "analyze" && !c.Synchronized);

                    lblAnalyze.Visible = true;
                    lblAnalyze.Text    = $"You have called the Analyze command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "checksum"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "checksum" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "checksum" && !c.Synchronized);

                    lblChecksum.Visible = true;
                    lblChecksum.Text    = $"You have called the Checksum command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "compare"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "compare" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "compare" && !c.Synchronized);

                    lblCompare.Visible = true;
                    lblCompare.Text    = $"You have called the Compare command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "convert-image"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "convert-image" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "convert-image" && !c.Synchronized);

                    lblConvertImage.Visible = true;
                    lblConvertImage.Text    = $"You have called the Convert-Image command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "create-sidecar"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "create-sidecar" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "create-sidecar" && !c.Synchronized);

                    lblCreateSidecar.Visible = true;
                    lblCreateSidecar.Text    = $"You have called the Create-Sidecar command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "decode"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "decode" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "decode" && !c.Synchronized);

                    lblDecode.Visible = true;
                    lblDecode.Text    = $"You have called the Decode command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "device-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "device-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "device-info" && !c.Synchronized);

                    lblDeviceInfo.Visible = true;
                    lblDeviceInfo.Text    = $"You have called the Device-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "device-report"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "device-report" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "device-report" && !c.Synchronized);

                    lblDeviceReport.Visible = true;
                    lblDeviceReport.Text    = $"You have called the Device-Report command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "dump-media"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "dump-media" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "dump-media" && !c.Synchronized);

                    lblDumpMedia.Visible = true;
                    lblDumpMedia.Text    = $"You have called the Dump-Media command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "entropy"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "entropy" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "entropy" && !c.Synchronized);

                    lblEntropy.Visible = true;
                    lblEntropy.Text    = $"You have called the Entropy command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "formats"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "formats" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "formats" && !c.Synchronized);

                    lblFormats.Visible = true;
                    lblFormats.Text    = $"You have called the Formats command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "image-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "image-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "image-info" && !c.Synchronized);

                    lblImageInfo.Visible = true;
                    lblImageInfo.Text    = $"You have called the Image-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "media-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "media-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "media-info" && !c.Synchronized);

                    lblMediaInfo.Visible = true;
                    lblMediaInfo.Text    = $"You have called the Media-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "media-scan"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "media-scan" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "media-scan" && !c.Synchronized);

                    lblMediaScan.Visible = true;
                    lblMediaScan.Text    = $"You have called the Media-Scan command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "printhex"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "printhex" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "printhex" && !c.Synchronized);

                    lblPrintHex.Visible = true;
                    lblPrintHex.Text    = $"You have called the Print-Hex command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "verify"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "verify" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "verify" && !c.Synchronized);

                    lblVerify.Visible = true;
                    lblVerify.Text    = $"You have called the Verify command {count} times";
                }

                tabCommands.Visible = lblAnalyze.Visible || lblChecksum.Visible || lblCompare.Visible ||
                                      lblConvertImage.Visible || lblCreateSidecar.Visible || lblDecode.Visible ||
                                      lblDeviceInfo.Visible || lblDeviceReport.Visible || lblDumpMedia.Visible ||
                                      lblEntropy.Visible || lblFormats.Visible || lblImageInfo.Visible ||
                                      lblMediaInfo.Visible || lblMediaScan.Visible || lblPrintHex.Visible ||
                                      lblVerify.Visible;
            }

            if (ctx.Filters.Any())
            {
                tabFilters.Visible = true;

                var filterList = new TreeGridItemCollection();

                treeFilters.Columns.Add(new GridColumn
                {
                    HeaderText = "Filter", DataCell = new TextBoxCell(0)
                });

                treeFilters.Columns.Add(new GridColumn
                {
                    HeaderText = "Times found", DataCell = new TextBoxCell(1)
                });

                treeFilters.AllowMultipleSelection = false;
                treeFilters.ShowHeader             = true;
                treeFilters.DataStore = filterList;

                foreach (string nvs in ctx.Filters.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Filters.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Filters.LongCount(c => c.Name == nvs && !c.Synchronized);

                    filterList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            nvs, count
                        }
                    });
                }
            }

            if (ctx.MediaFormats.Any())
            {
                tabFormats.Visible = true;

                var formatList = new TreeGridItemCollection();

                treeFormats.Columns.Add(new GridColumn
                {
                    HeaderText = "Format", DataCell = new TextBoxCell(0)
                });

                treeFormats.Columns.Add(new GridColumn
                {
                    HeaderText = "Times found", DataCell = new TextBoxCell(1)
                });

                treeFormats.AllowMultipleSelection = false;
                treeFormats.ShowHeader             = true;
                treeFormats.DataStore = formatList;

                foreach (string nvs in ctx.MediaFormats.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.MediaFormats.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.MediaFormats.LongCount(c => c.Name == nvs && !c.Synchronized);

                    formatList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            nvs, count
                        }
                    });
                }
            }

            if (ctx.Partitions.Any())
            {
                tabPartitions.Visible = true;

                var partitionList = new TreeGridItemCollection();

                treePartitions.Columns.Add(new GridColumn
                {
                    HeaderText = "Filter", DataCell = new TextBoxCell(0)
                });

                treePartitions.Columns.Add(new GridColumn
                {
                    HeaderText = "Times found", DataCell = new TextBoxCell(1)
                });

                treePartitions.AllowMultipleSelection = false;
                treePartitions.ShowHeader             = true;
                treePartitions.DataStore = partitionList;

                foreach (string nvs in ctx.Partitions.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Partitions.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Partitions.LongCount(c => c.Name == nvs && !c.Synchronized);

                    partitionList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            nvs, count
                        }
                    });
                }
            }

            if (ctx.Filesystems.Any())
            {
                tabFilesystems.Visible = true;

                var filesystemList = new TreeGridItemCollection();

                treeFilesystems.Columns.Add(new GridColumn
                {
                    HeaderText = "Filesystem", DataCell = new TextBoxCell(0)
                });

                treeFilesystems.Columns.Add(new GridColumn
                {
                    HeaderText = "Times found", DataCell = new TextBoxCell(1)
                });

                treeFilesystems.AllowMultipleSelection = false;
                treeFilesystems.ShowHeader             = true;
                treeFilesystems.DataStore = filesystemList;

                foreach (string nvs in ctx.Filesystems.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Filesystems.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Filesystems.LongCount(c => c.Name == nvs && !c.Synchronized);

                    filesystemList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            nvs, count
                        }
                    });
                }
            }

            if (ctx.SeenDevices.Any())
            {
                tabDevices.Visible = true;

                var deviceList = new TreeGridItemCollection();

                treeDevices.Columns.Add(new GridColumn
                {
                    HeaderText = "Device", DataCell = new TextBoxCell(0)
                });

                treeDevices.Columns.Add(new GridColumn
                {
                    HeaderText = "Manufacturer", DataCell = new TextBoxCell(1)
                });

                treeDevices.Columns.Add(new GridColumn
                {
                    HeaderText = "Revision", DataCell = new TextBoxCell(2)
                });

                treeDevices.Columns.Add(new GridColumn
                {
                    HeaderText = "Bus", DataCell = new TextBoxCell(3)
                });

                treeDevices.AllowMultipleSelection = false;
                treeDevices.ShowHeader             = true;
                treeDevices.DataStore = deviceList;

                foreach (DeviceStat ds in ctx.SeenDevices.OrderBy(n => n.Manufacturer).ThenBy(n => n.Manufacturer).
                         ThenBy(n => n.Revision).ThenBy(n => n.Bus))
                {
                    deviceList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            ds.Model, ds.Manufacturer, ds.Revision, ds.Bus
                        }
                    });
                }
            }

            if (!ctx.Medias.Any())
            {
                return;
            }

            tabMedias.Visible = true;

            var mediaList = new TreeGridItemCollection();

            treeMedias.Columns.Add(new GridColumn
            {
                HeaderText = "Media", DataCell = new TextBoxCell(0)
            });

            treeMedias.Columns.Add(new GridColumn
            {
                HeaderText = "Times found", DataCell = new TextBoxCell(1)
            });

            treeMedias.Columns.Add(new GridColumn
            {
                HeaderText = "Type", DataCell = new TextBoxCell(2)
            });

            treeMedias.AllowMultipleSelection = false;
            treeMedias.ShowHeader             = true;
            treeMedias.DataStore = mediaList;

            foreach (string media in ctx.Medias.OrderBy(ms => ms.Type).Select(ms => ms.Type).Distinct())
            {
                ulong count = ctx.Medias.Where(c => c.Type == media && c.Synchronized && c.Real).Select(c => c.Count).
                              FirstOrDefault();

                count += (ulong)ctx.Medias.LongCount(c => c.Type == media && !c.Synchronized && c.Real);

                if (count > 0)
                {
                    mediaList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            media, count, "real"
                        }
                    });
                }

                count = ctx.Medias.Where(c => c.Type == media && c.Synchronized && !c.Real).Select(c => c.Count).
                        FirstOrDefault();

                count += (ulong)ctx.Medias.LongCount(c => c.Type == media && !c.Synchronized && !c.Real);

                if (count == 0)
                {
                    continue;
                }

                mediaList.Add(new TreeGridItem
                {
                    Values = new object[]
                    {
                        media, count, "image"
                    }
                });
            }
        }
Exemplo n.º 9
0
        private void InitializeComponent()
        {
            #region Initialization

            searchTextBox = new TextBox
            {
                Size = new Size(268, -1)
            };

            #region Commands

            searchClearCommand = new Command {
                MenuText = "Clear"
            };

            cancelCommand = new Command {
                MenuText = "Cancel"
            };

            openCommand = new Command {
                MenuText = "Open"
            };
            openWithCommand = new Command {
                MenuText = "Open with"
            };

            saveCommand = new Command {
                MenuText = "Save", Shortcut = SaveHotKey
            };
            saveAsCommand = new Command {
                MenuText = "Save As", Shortcut = SaveAsHotKey
            };

            extractDirectoryCommand = new Command {
                MenuText = "Extract", Image = MenuExportResource
            };
            replaceDirectoryCommand = new Command {
                MenuText = "Replace", Image = MenuImportResource
            };
            renameDirectoryCommand = new Command {
                MenuText = "Rename", Image = MenuEditResource
            };
            deleteDirectoryCommand = new Command {
                MenuText = "Delete", Image = MenuDeleteResource
            };
            addDirectoryCommand = new Command {
                MenuText = "Add", Image = MenuAddResource
            };

            extractFileCommand = new Command {
                MenuText = "Extract", Image = MenuExportResource
            };
            replaceFileCommand = new Command {
                MenuText = "Replace", Image = MenuImportResource
            };
            renameFileCommand = new Command {
                MenuText = "Rename", Image = MenuEditResource
            };
            deleteFileCommand = new Command {
                MenuText = "Delete", Image = MenuDeleteResource
            };

            #endregion

            #region Folders

            var folderContext = new ContextMenu
            {
                Items =
                {
                    extractDirectoryCommand,
                    replaceDirectoryCommand,
                    renameDirectoryCommand,
                    addDirectoryCommand,
                    deleteDirectoryCommand
                }
            };

            folders    = new TreeGridItemCollection();
            folderView = new TreeGridView
            {
                ContextMenu = folderContext,

                DataStore = folders,
                Columns   =
                {
                    new GridColumn
                    {
                        DataCell = new ImageTextCell(0, 1)
                    }
                },
                AllowColumnReordering = false
            };

            #endregion

            #region Files

            openWithMenuItem = new ButtonMenuItem {
                Text = "Open with", Command = openWithCommand
            };
            var fileContext = new ContextMenu
            {
                Items =
                {
                    openCommand,
                    openWithMenuItem,

                    new SeparatorMenuItem(),

                    extractFileCommand,
                    replaceFileCommand,
                    renameFileCommand,
                    deleteFileCommand
                }
            };

            files    = new ObservableCollection <FileElement>();
            fileView = new GridView <FileElement>
            {
                ShowHeader             = true,
                AllowMultipleSelection = true,
                BackgroundColor        = KnownColors.White,

                ContextMenu = fileContext,

                Columns =
                {
                    new GridColumn
                    {
                        DataCell   = new TextBoxCell(nameof(FileElement.Name)),
                        HeaderText = "Name",
                        Sortable   = true,
                        AutoSize   = true
                    },
                    new GridColumn
                    {
                        DataCell   = new TextBoxCell(nameof(FileElement.Size)),
                        HeaderText = "Size",
                        Sortable   = true,
                        AutoSize   = true
                    }
                },

                DataStore = files
            };

            #endregion

            #region Buttons

            searchClearButton = new Button
            {
                Text    = "X",
                Size    = new Size(22, -1),
                Command = searchClearCommand
            };

            cancelButton = new Button
            {
                Text    = "Cancel",
                Command = cancelCommand
            };

            saveButton = new ButtonToolStripItem
            {
                Command = saveCommand,
                Image   = MenuSaveResource
            };

            saveAsButton = new ButtonToolStripItem
            {
                Command = saveAsCommand,
                Image   = MenuSaveAsResource
            };

            extractButton = new ButtonToolStripItem
            {
                Command = extractFileCommand,
                Image   = MenuExportResource
            };

            replaceButton = new ButtonToolStripItem
            {
                Command = replaceFileCommand,
                Image   = MenuImportResource
            };

            renameButton = new ButtonToolStripItem
            {
                Command = renameFileCommand,
                Image   = MenuExportResource
            };

            deleteButton = new ButtonToolStripItem
            {
                Command = deleteFileCommand,
                Image   = MenuDeleteResource
            };

            #endregion

            #endregion

            #region Content

            var archiveToolStrip = new ToolStrip
            {
                BackgroundColor = KnownColors.White,
                Items           =
                {
                    saveButton,
                    saveAsButton
                }
            };

            var mainContent = new TableLayout
            {
                Spacing = new Size(3, 3),
                Rows    =
                {
                    // Searchbar and file toolstrip
                    new TableRow
                    {
                        Cells =
                        {
                            // Searchbar
                            new StackLayout
                            {
                                Spacing     = 3,
                                Orientation = Orientation.Horizontal,
                                Items       =
                                {
                                    searchTextBox,
                                    searchClearButton
                                }
                            },

                            // file toolstrip
                            new ToolStrip
                            {
                                Size            = new SizeF(-1, ToolStripItem.Height + 6),
                                BackgroundColor = KnownColors.White,
                                Items           =
                                {
                                    extractButton,
                                    replaceButton,
                                    renameButton,
                                    deleteButton
                                }
                            },
                        }
                    },

                    // Folder and file view
                    new TableRow
                    {
                        Cells =
                        {
                            folderView,
                            fileView
                        }
                    }
                }
            };

            Content = new TableLayout
            {
                Spacing = new Size(3, 3),
                Rows    =
                {
                    new TableRow(new Panel {
                        Content = archiveToolStrip, Size = new Size(-1, (int)ToolStripItem.Height + 6)
                    }),
                    new TableRow           {
                        Cells =            { new TableCell(mainContent)
                                             {
                                                 ScaleWidth = true
                                             } }, ScaleHeight = true
                    }
                }
            };

            #endregion
        }
Exemplo n.º 10
0
        public pnlImageInfo(string imagePath, IFilter filter, IMediaImage imageFormat)
        {
            this.imagePath   = imagePath;
            this.filter      = filter;
            this.imageFormat = imageFormat;
            XamlReader.Load(this);

            Stream logo =
                ResourceHandler.GetResourceStream($"Aaru.Gui.Assets.Logos.Media.{imageFormat.Info.MediaType}.svg");

            /*            if(logo != null)
             *          {
             *              svgMediaLogo.SvgStream = logo;
             *              svgMediaLogo.Visible   = true;
             *          }
             *          else
             *          {*/
            logo = ResourceHandler.GetResourceStream($"Aaru.Gui.Assets.Logos.Media.{imageFormat.Info.MediaType}.png");

            if (logo != null)
            {
                imgMediaLogo.Image   = new Bitmap(logo);
                imgMediaLogo.Visible = true;
            }

            //}

            lblImagePath.Text   = $"Path: {imagePath}";
            lblFilter.Text      = $"Filter: {filter.Name}";
            lblImageFormat.Text = $"Image format identified by {imageFormat.Name} ({imageFormat.Id}).";

            lblImageFormat.Text = !string.IsNullOrWhiteSpace(imageFormat.Info.Version)
                                      ? $"Format: {imageFormat.Format} version {imageFormat.Info.Version}"
                                      : $"Format: {imageFormat.Format}";

            lblImageSize.Text = $"Image without headers is {imageFormat.Info.ImageSize} bytes long";

            lblSectors.Text =
                $"Contains a media of {imageFormat.Info.Sectors} sectors with a maximum sector size of {imageFormat.Info.SectorSize} bytes (if all sectors are of the same size this would be {imageFormat.Info.Sectors * imageFormat.Info.SectorSize} bytes)";

            lblMediaType.Text =
                $"Contains a media of type {imageFormat.Info.MediaType} and XML type {imageFormat.Info.XmlMediaType}";

            lblHasPartitions.Text = $"{(imageFormat.Info.HasPartitions ? "Has" : "Doesn't have")} partitions";
            lblHasSessions.Text   = $"{(imageFormat.Info.HasSessions ? "Has" : "Doesn't have")} sessions";

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application))
            {
                lblApplication.Visible = true;

                lblApplication.Text = !string.IsNullOrWhiteSpace(imageFormat.Info.ApplicationVersion)
                                          ? $"Was created with {imageFormat.Info.Application} version {imageFormat.Info.ApplicationVersion}"
                                          : $"Was created with {imageFormat.Info.Application}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Creator))
            {
                lblCreator.Visible = true;
                lblCreator.Text    = $"Created by: {imageFormat.Info.Creator}";
            }

            if (imageFormat.Info.CreationTime != DateTime.MinValue)
            {
                lblCreationTime.Visible = true;
                lblCreationTime.Text    = $"Created on {imageFormat.Info.CreationTime}";
            }

            if (imageFormat.Info.LastModificationTime != DateTime.MinValue)
            {
                lblLastModificationTime.Visible = true;
                lblLastModificationTime.Text    = $"Last modified on {imageFormat.Info.LastModificationTime}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Comments))
            {
                grpComments.Visible = true;
                txtComments.Text    = imageFormat.Info.Comments;
            }

            if (imageFormat.Info.MediaSequence != 0 &&
                imageFormat.Info.LastMediaSequence != 0)
            {
                lblMediaSequence.Visible = true;

                lblMediaSequence.Text =
                    $"Media is number {imageFormat.Info.MediaSequence} on a set of {imageFormat.Info.LastMediaSequence} medias";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
            {
                lblMediaTitle.Visible = true;
                lblMediaTitle.Text    = $"Media title: {imageFormat.Info.MediaTitle}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaManufacturer))
            {
                lblMediaManufacturer.Visible = true;
                lblMediaManufacturer.Text    = $"Media manufacturer: {imageFormat.Info.MediaManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaModel))
            {
                lblMediaModel.Visible = true;
                lblMediaModel.Text    = $"Media model: {imageFormat.Info.MediaModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaSerialNumber))
            {
                lblMediaSerialNumber.Visible = true;
                lblMediaSerialNumber.Text    = $"Media serial number: {imageFormat.Info.MediaSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaBarcode))
            {
                lblMediaBarcode.Visible = true;
                lblMediaBarcode.Text    = $"Media barcode: {imageFormat.Info.MediaBarcode}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaPartNumber))
            {
                lblMediaPartNumber.Visible = true;
                lblMediaPartNumber.Text    = $"Media part number: {imageFormat.Info.MediaPartNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveManufacturer))
            {
                lblDriveManufacturer.Visible = true;
                lblDriveManufacturer.Text    = $"Drive manufacturer: {imageFormat.Info.DriveManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveModel))
            {
                lblDriveModel.Visible = true;
                lblDriveModel.Text    = $"Drive model: {imageFormat.Info.DriveModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveSerialNumber))
            {
                lblDriveSerialNumber.Visible = true;
                lblDriveSerialNumber.Text    = $"Drive serial number: {imageFormat.Info.DriveSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveFirmwareRevision))
            {
                lblDriveFirmwareRevision.Visible = true;
                lblDriveFirmwareRevision.Text    = $"Drive firmware info: {imageFormat.Info.DriveFirmwareRevision}";
            }

            if (imageFormat.Info.Cylinders > 0 &&
                imageFormat.Info.Heads > 0 &&
                imageFormat.Info.SectorsPerTrack > 0 &&
                imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
                (!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
            {
                lblMediaGeometry.Visible = true;

                lblMediaGeometry.Text =
                    $"Media geometry: {imageFormat.Info.Cylinders} cylinders, {imageFormat.Info.Heads} heads, {imageFormat.Info.SectorsPerTrack} sectors per track";
            }

            grpMediaInfo.Visible = lblMediaSequence.Visible || lblMediaTitle.Visible ||
                                   lblMediaManufacturer.Visible ||
                                   lblMediaModel.Visible || lblMediaSerialNumber.Visible ||
                                   lblMediaBarcode.Visible ||
                                   lblMediaPartNumber.Visible;

            grpDriveInfo.Visible = lblDriveManufacturer.Visible || lblDriveModel.Visible ||
                                   lblDriveSerialNumber.Visible || lblDriveFirmwareRevision.Visible ||
                                   lblMediaGeometry.Visible;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Count > 0)
            {
                var mediaTagList = new TreeGridItemCollection();

                treeMediaTags.Columns.Add(new GridColumn
                {
                    HeaderText = "Tag", DataCell = new TextBoxCell(0)
                });

                treeMediaTags.AllowMultipleSelection = false;
                treeMediaTags.ShowHeader             = false;
                treeMediaTags.DataStore = mediaTagList;

                foreach (MediaTagType tag in imageFormat.Info.ReadableMediaTags.OrderBy(t => t))
                {
                    mediaTagList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            tag.ToString()
                        }
                    });
                }

                grpMediaTags.Visible = true;
            }

            if (imageFormat.Info.ReadableSectorTags != null &&
                imageFormat.Info.ReadableSectorTags.Count > 0)
            {
                var sectorTagList = new TreeGridItemCollection();

                treeSectorTags.Columns.Add(new GridColumn
                {
                    HeaderText = "Tag", DataCell = new TextBoxCell(0)
                });

                treeSectorTags.AllowMultipleSelection = false;
                treeSectorTags.ShowHeader             = false;
                treeSectorTags.DataStore = sectorTagList;

                foreach (SectorTagType tag in imageFormat.Info.ReadableSectorTags.OrderBy(t => t))
                {
                    sectorTagList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            tag.ToString()
                        }
                    });
                }

                grpSectorTags.Visible = true;
            }

            PeripheralDeviceTypes scsiDeviceType = PeripheralDeviceTypes.DirectAccess;

            byte[]  scsiInquiryData = null;
            Inquiry?scsiInquiry     = null;

            Modes.DecodedMode?scsiMode        = null;
            byte[]            scsiModeSense6  = null;
            byte[]            scsiModeSense10 = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_INQUIRY))
            {
                scsiInquiryData = imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY);

                scsiDeviceType = (PeripheralDeviceTypes)(scsiInquiryData[0] & 0x1F);

                scsiInquiry = Inquiry.Decode(scsiInquiryData);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_6))
            {
                scsiModeSense6 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6);
                scsiMode       = Modes.DecodeMode6(scsiModeSense6, scsiDeviceType);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_10))
            {
                scsiModeSense10 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10);
                scsiMode        = Modes.DecodeMode10(scsiModeSense10, scsiDeviceType);
            }

            var tabScsiInfo = new tabScsiInfo();

            tabScsiInfo.LoadData(scsiInquiryData, scsiInquiry, null, scsiMode, scsiDeviceType, scsiModeSense6,
                                 scsiModeSense10, null);

            tabInfos.Pages.Add(tabScsiInfo);

            byte[] ataIdentify   = null;
            byte[] atapiIdentify = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATA_IDENTIFY))
            {
                ataIdentify = imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATAPI_IDENTIFY))
            {
                atapiIdentify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);
            }

            var tabAtaInfo = new tabAtaInfo();

            tabAtaInfo.LoadData(ataIdentify, atapiIdentify, null);
            tabInfos.Pages.Add(tabAtaInfo);

            byte[]                toc                  = null;
            TOC.CDTOC?            decodedToc           = null;
            byte[]                fullToc              = null;
            FullTOC.CDFullTOC?    decodedFullToc       = null;
            byte[]                pma                  = null;
            byte[]                atip                 = null;
            ATIP.CDATIP?          decodedAtip          = null;
            byte[]                cdtext               = null;
            CDTextOnLeadIn.CDText?decodedCdText        = null;
            string                mediaCatalogueNumber = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TOC))
            {
                toc = imageFormat.ReadDiskTag(MediaTagType.CD_TOC);

                if (toc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0));

                    if (dataLen + 2 != toc.Length)
                    {
                        byte[] tmp = new byte[toc.Length + 2];
                        Array.Copy(toc, 0, tmp, 2, toc.Length);
                        tmp[0] = (byte)((toc.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(toc.Length & 0xFF);
                        toc    = tmp;
                    }

                    decodedToc = TOC.Decode(toc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_FullTOC))
            {
                fullToc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC);

                if (fullToc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(fullToc, 0));

                    if (dataLen + 2 != fullToc.Length)
                    {
                        byte[] tmp = new byte[fullToc.Length + 2];
                        Array.Copy(fullToc, 0, tmp, 2, fullToc.Length);
                        tmp[0]  = (byte)((fullToc.Length & 0xFF00) >> 8);
                        tmp[1]  = (byte)(fullToc.Length & 0xFF);
                        fullToc = tmp;
                    }

                    decodedFullToc = FullTOC.Decode(fullToc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_PMA))
            {
                pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA);

                if (pma.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0));

                    if (dataLen + 2 != pma.Length)
                    {
                        byte[] tmp = new byte[pma.Length + 2];
                        Array.Copy(pma, 0, tmp, 2, pma.Length);
                        tmp[0] = (byte)((pma.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(pma.Length & 0xFF);
                        pma    = tmp;
                    }
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_ATIP))
            {
                atip = imageFormat.ReadDiskTag(MediaTagType.CD_ATIP);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(atip, 0));

                if (dataLen + 4 != atip.Length)
                {
                    byte[] tmp = new byte[atip.Length + 4];
                    Array.Copy(atip, 0, tmp, 4, atip.Length);
                    tmp[0] = (byte)((atip.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((atip.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((atip.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(atip.Length & 0xFF);
                    atip   = tmp;
                }

                decodedAtip = ATIP.Decode(atip);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TEXT))
            {
                cdtext = imageFormat.ReadDiskTag(MediaTagType.CD_TEXT);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(cdtext, 0));

                if (dataLen + 4 != cdtext.Length)
                {
                    byte[] tmp = new byte[cdtext.Length + 4];
                    Array.Copy(cdtext, 0, tmp, 4, cdtext.Length);
                    tmp[0] = (byte)((cdtext.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((cdtext.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((cdtext.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(cdtext.Length & 0xFF);
                    cdtext = tmp;
                }

                decodedCdText = CDTextOnLeadIn.Decode(cdtext);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_MCN))
            {
                byte[] mcn = imageFormat.ReadDiskTag(MediaTagType.CD_MCN);

                mediaCatalogueNumber = Encoding.UTF8.GetString(mcn);
            }

            var tabCompactDiscInfo = new tabCompactDiscInfo();

            tabCompactDiscInfo.LoadData(toc, atip, null, null, fullToc, pma, cdtext, decodedToc, decodedAtip, null,
                                        decodedFullToc, decodedCdText, null, mediaCatalogueNumber, null);

            tabInfos.Pages.Add(tabCompactDiscInfo);

            byte[] dvdPfi = null;
            byte[] dvdDmi = null;
            byte[] dvdCmi = null;
            byte[] hddvdCopyrightInformation = null;
            byte[] dvdBca = null;
            PFI.PhysicalFormatInformation?decodedPfi = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_PFI))
            {
                dvdPfi     = imageFormat.ReadDiskTag(MediaTagType.DVD_PFI);
                decodedPfi = PFI.Decode(dvdPfi);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_DMI))
            {
                dvdDmi = imageFormat.ReadDiskTag(MediaTagType.DVD_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_CMI))
            {
                dvdCmi = imageFormat.ReadDiskTag(MediaTagType.DVD_CMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_CPI))
            {
                hddvdCopyrightInformation = imageFormat.ReadDiskTag(MediaTagType.HDDVD_CPI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_BCA))
            {
                dvdBca = imageFormat.ReadDiskTag(MediaTagType.DVD_BCA);
            }

            var tabDvdInfo = new tabDvdInfo();

            tabDvdInfo.LoadData(imageFormat.Info.MediaType, dvdPfi, dvdDmi, dvdCmi, hddvdCopyrightInformation, dvdBca,
                                null, decodedPfi);

            tabInfos.Pages.Add(tabDvdInfo);

            byte[] dvdRamDds                     = null;
            byte[] dvdRamCartridgeStatus         = null;
            byte[] dvdRamSpareArea               = null;
            byte[] lastBorderOutRmd              = null;
            byte[] dvdPreRecordedInfo            = null;
            byte[] dvdrMediaIdentifier           = null;
            byte[] dvdrPhysicalInformation       = null;
            byte[] hddvdrMediumStatus            = null;
            byte[] dvdrLayerCapacity             = null;
            byte[] dvdrDlMiddleZoneStart         = null;
            byte[] dvdrDlJumpIntervalSize        = null;
            byte[] dvdrDlManualLayerJumpStartLba = null;
            byte[] dvdPlusAdip                   = null;
            byte[] dvdPlusDcb                    = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_DDS))
            {
                dvdRamDds = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_MediumStatus))
            {
                dvdRamCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_SpareArea))
            {
                dvdRamSpareArea = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_RMD))
            {
                lastBorderOutRmd = imageFormat.ReadDiskTag(MediaTagType.DVDR_RMD);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PreRecordedInfo))
            {
                dvdPreRecordedInfo = imageFormat.ReadDiskTag(MediaTagType.DVDR_PreRecordedInfo);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_MediaIdentifier))
            {
                dvdrMediaIdentifier = imageFormat.ReadDiskTag(MediaTagType.DVDR_MediaIdentifier);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PFI))
            {
                dvdrPhysicalInformation = imageFormat.ReadDiskTag(MediaTagType.DVDR_PFI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_MediumStatus))
            {
                hddvdrMediumStatus = imageFormat.ReadDiskTag(MediaTagType.HDDVD_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_LayerCapacity))
            {
                dvdrLayerCapacity = imageFormat.ReadDiskTag(MediaTagType.DVDDL_LayerCapacity);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_MiddleZoneAddress))
            {
                dvdrDlMiddleZoneStart = imageFormat.ReadDiskTag(MediaTagType.DVDDL_MiddleZoneAddress);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_JumpIntervalSize))
            {
                dvdrDlJumpIntervalSize = imageFormat.ReadDiskTag(MediaTagType.DVDDL_JumpIntervalSize);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_ManualLayerJumpLBA))
            {
                dvdrDlManualLayerJumpStartLba = imageFormat.ReadDiskTag(MediaTagType.DVDDL_ManualLayerJumpLBA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_ADIP))
            {
                dvdPlusAdip = imageFormat.ReadDiskTag(MediaTagType.DVD_ADIP);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DCB))
            {
                dvdPlusDcb = imageFormat.ReadDiskTag(MediaTagType.DCB);
            }

            var tabDvdWritableInfo = new tabDvdWritableInfo();

            tabDvdWritableInfo.LoadData(imageFormat.Info.MediaType, dvdRamDds, dvdRamCartridgeStatus, dvdRamSpareArea,
                                        lastBorderOutRmd, dvdPreRecordedInfo, dvdrMediaIdentifier,
                                        dvdrPhysicalInformation, hddvdrMediumStatus, null, dvdrLayerCapacity,
                                        dvdrDlMiddleZoneStart, dvdrDlJumpIntervalSize, dvdrDlManualLayerJumpStartLba,
                                        null, dvdPlusAdip, dvdPlusDcb);

            tabInfos.Pages.Add(tabDvdWritableInfo);

            byte[] blurayBurstCuttingArea = null;
            byte[] blurayCartridgeStatus  = null;
            byte[] blurayDds                  = null;
            byte[] blurayDiscInformation      = null;
            byte[] blurayPowResources         = null;
            byte[] bluraySpareAreaInformation = null;
            byte[] blurayTrackResources       = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_BCA))
            {
                blurayBurstCuttingArea = imageFormat.ReadDiskTag(MediaTagType.BD_BCA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_CartridgeStatus))
            {
                blurayCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.BD_CartridgeStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DDS))
            {
                blurayDds = imageFormat.ReadDiskTag(MediaTagType.BD_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DI))
            {
                blurayDiscInformation = imageFormat.ReadDiskTag(MediaTagType.BD_DI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_POWResourcesInformation))
            {
                blurayPowResources = imageFormat.ReadDiskTag(MediaTagType.MMC_POWResourcesInformation);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_SpareArea))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.BD_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_TrackResourcesInformation))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.MMC_TrackResourcesInformation);
            }

            var tabBlurayInfo = new tabBlurayInfo();

            tabBlurayInfo.LoadData(blurayDiscInformation, blurayBurstCuttingArea, blurayDds, blurayCartridgeStatus,
                                   bluraySpareAreaInformation, blurayPowResources, blurayTrackResources, null, null);

            tabInfos.Pages.Add(tabBlurayInfo);

            byte[]            xboxDmi                   = null;
            byte[]            xboxSecuritySector        = null;
            SS.SecuritySector?decodedXboxSecuritySector = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_DMI))
            {
                xboxDmi = imageFormat.ReadDiskTag(MediaTagType.Xbox_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_SecuritySector))
            {
                xboxSecuritySector        = imageFormat.ReadDiskTag(MediaTagType.Xbox_SecuritySector);
                decodedXboxSecuritySector = SS.Decode(xboxSecuritySector);
            }

            var tabXboxInfo = new tabXboxInfo();

            tabXboxInfo.LoadData(null, xboxDmi, xboxSecuritySector, decodedXboxSecuritySector);
            tabInfos.Pages.Add(tabXboxInfo);

            byte[] pcmciaCis = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.PCMCIA_CIS))
            {
                pcmciaCis = imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);
            }

            var tabPcmciaInfo = new tabPcmciaInfo();

            tabPcmciaInfo.LoadData(pcmciaCis);
            tabInfos.Pages.Add(tabPcmciaInfo);

            DeviceType deviceType = DeviceType.Unknown;

            byte[] cid         = null;
            byte[] csd         = null;
            byte[] ocr         = null;
            byte[] extendedCsd = null;
            byte[] scr         = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.SD_CID);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.SD_CSD);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.SD_OCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_SCR))
            {
                scr        = imageFormat.ReadDiskTag(MediaTagType.SD_SCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.MMC_CID);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.MMC_CSD);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.MMC_OCR);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_ExtendedCSD))
            {
                extendedCsd = imageFormat.ReadDiskTag(MediaTagType.MMC_ExtendedCSD);
                deviceType  = DeviceType.MMC;
            }

            var tabSdMmcInfo = new tabSdMmcInfo();

            tabSdMmcInfo.LoadData(deviceType, cid, csd, ocr, extendedCsd, scr);
            tabInfos.Pages.Add(tabSdMmcInfo);

            if (imageFormat is IOpticalMediaImage opticalMediaImage)
            {
                try
                {
                    if (opticalMediaImage.Sessions != null &&
                        opticalMediaImage.Sessions.Count > 0)
                    {
                        var sessionList = new TreeGridItemCollection();

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "Session", DataCell = new TextBoxCell(0)
                        });

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "First track", DataCell = new TextBoxCell(1)
                        });

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "Last track", DataCell = new TextBoxCell(2)
                        });

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "Start", DataCell = new TextBoxCell(3)
                        });

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "End", DataCell = new TextBoxCell(4)
                        });

                        treeSessions.AllowMultipleSelection = false;
                        treeSessions.ShowHeader             = true;
                        treeSessions.DataStore = sessionList;

                        foreach (Session session in opticalMediaImage.Sessions)
                        {
                            sessionList.Add(new TreeGridItem
                            {
                                Values = new object[]
                                {
                                    session.SessionSequence, session.StartTrack, session.EndTrack, session.StartSector,
                                    session.EndSector
                                }
                            });
                        }

                        tabSessions.Visible = true;
                    }
                }
                catch
                {
                    // ignored
                }

                try
                {
                    if (opticalMediaImage.Tracks != null &&
                        opticalMediaImage.Tracks.Count > 0)
                    {
                        var tracksList = new TreeGridItemCollection();

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Track", DataCell = new TextBoxCell(0)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Type", DataCell = new TextBoxCell(1)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Bps", DataCell = new TextBoxCell(2)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Raw bps", DataCell = new TextBoxCell(3)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Subchannel", DataCell = new TextBoxCell(4)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Pregap", DataCell = new TextBoxCell(5)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Start", DataCell = new TextBoxCell(6)
                        });

                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "End", DataCell = new TextBoxCell(7)
                        });

                        treeTracks.AllowMultipleSelection = false;
                        treeTracks.ShowHeader             = true;
                        treeTracks.DataStore = tracksList;

                        foreach (Track track in opticalMediaImage.Tracks)
                        {
                            tracksList.Add(new TreeGridItem
                            {
                                Values = new object[]
                                {
                                    track.TrackSequence, track.TrackType, track.TrackBytesPerSector,
                                    track.TrackRawBytesPerSector, track.TrackSubchannelType, track.TrackPregap,
                                    track.TrackStartSector, track.TrackEndSector
                                }
                            });
                        }

                        tabTracks.Visible = true;
                    }
                }
                catch
                {
                    // ignored
                }
            }

            if (imageFormat.DumpHardware == null)
            {
                return;
            }

            var dumpHardwareList = new TreeGridItemCollection();

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Manufacturer", DataCell = new TextBoxCell(0)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Model", DataCell = new TextBoxCell(1)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Serial", DataCell = new TextBoxCell(2)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Software", DataCell = new TextBoxCell(3)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Version", DataCell = new TextBoxCell(4)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Operating system", DataCell = new TextBoxCell(5)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Start", DataCell = new TextBoxCell(6)
            });

            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "End", DataCell = new TextBoxCell(7)
            });

            treeDumpHardware.AllowMultipleSelection = false;
            treeDumpHardware.ShowHeader             = true;
            treeDumpHardware.DataStore = dumpHardwareList;

            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                foreach (ExtentType extent in dump.Extents)
                {
                    dumpHardwareList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            dump.Manufacturer, dump.Model, dump.Serial, dump.Software.Name, dump.Software.Version,
                            dump.Software.OperatingSystem, extent.Start, extent.End
                        }
                    });
                }
            }

            tabDumpHardware.Visible = true;
        }
Exemplo n.º 11
0
        internal void LoadData(byte[] pcmciaCis)
        {
            if (pcmciaCis == null)
            {
                return;
            }

            cis     = pcmciaCis;
            Visible = true;

            TreeGridItemCollection cisList = new TreeGridItemCollection();

            treePcmcia.Columns.Add(new GridColumn {
                HeaderText = "CIS", DataCell = new TextBoxCell(0)
            });

            treePcmcia.AllowMultipleSelection = false;
            treePcmcia.ShowHeader             = false;
            treePcmcia.DataStore = cisList;

            Tuple[] tuples = CIS.GetTuples(cis);
            if (tuples != null)
            {
                foreach (Tuple tuple in tuples)
                {
                    string tupleCode;
                    string tupleDescription;

                    switch (tuple.Code)
                    {
                    case TupleCodes.CISTPL_NULL:
                    case TupleCodes.CISTPL_END: continue;

                    case TupleCodes.CISTPL_DEVICEGEO:
                    case TupleCodes.CISTPL_DEVICEGEO_A:
                        tupleCode        = "Device Geometry Tuples";
                        tupleDescription = CIS.PrettifyDeviceGeometryTuple(tuple);
                        break;

                    case TupleCodes.CISTPL_MANFID:
                        tupleCode        = "Manufacturer Identification Tuple";
                        tupleDescription = CIS.PrettifyManufacturerIdentificationTuple(tuple);
                        break;

                    case TupleCodes.CISTPL_VERS_1:
                        tupleCode        = "Level 1 Version / Product Information Tuple";
                        tupleDescription = CIS.PrettifyLevel1VersionTuple(tuple);
                        break;

                    case TupleCodes.CISTPL_ALTSTR:
                    case TupleCodes.CISTPL_BAR:
                    case TupleCodes.CISTPL_BATTERY:
                    case TupleCodes.CISTPL_BYTEORDER:
                    case TupleCodes.CISTPL_CFTABLE_ENTRY:
                    case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
                    case TupleCodes.CISTPL_CHECKSUM:
                    case TupleCodes.CISTPL_CONFIG:
                    case TupleCodes.CISTPL_CONFIG_CB:
                    case TupleCodes.CISTPL_DATE:
                    case TupleCodes.CISTPL_DEVICE:
                    case TupleCodes.CISTPL_DEVICE_A:
                    case TupleCodes.CISTPL_DEVICE_OA:
                    case TupleCodes.CISTPL_DEVICE_OC:
                    case TupleCodes.CISTPL_EXTDEVIC:
                    case TupleCodes.CISTPL_FORMAT:
                    case TupleCodes.CISTPL_FORMAT_A:
                    case TupleCodes.CISTPL_FUNCE:
                    case TupleCodes.CISTPL_FUNCID:
                    case TupleCodes.CISTPL_GEOMETRY:
                    case TupleCodes.CISTPL_INDIRECT:
                    case TupleCodes.CISTPL_JEDEC_A:
                    case TupleCodes.CISTPL_JEDEC_C:
                    case TupleCodes.CISTPL_LINKTARGET:
                    case TupleCodes.CISTPL_LONGLINK_A:
                    case TupleCodes.CISTPL_LONGLINK_C:
                    case TupleCodes.CISTPL_LONGLINK_CB:
                    case TupleCodes.CISTPL_LONGLINK_MFC:
                    case TupleCodes.CISTPL_NO_LINK:
                    case TupleCodes.CISTPL_ORG:
                    case TupleCodes.CISTPL_PWR_MGMNT:
                    case TupleCodes.CISTPL_SPCL:
                    case TupleCodes.CISTPL_SWIL:
                    case TupleCodes.CISTPL_VERS_2:
                        tupleCode        = $"Undecoded tuple ID {tuple.Code}";
                        tupleDescription = $"Undecoded tuple ID {tuple.Code}";
                        break;

                    default:
                        tupleCode        = $"0x{(byte)tuple.Code:X2}";
                        tupleDescription = $"Found unknown tuple ID 0x{(byte)tuple.Code:X2}";
                        break;
                    }

                    cisList.Add(new TreeGridItem {
                        Values = new object[] { tupleCode, tupleDescription }
                    });
                }
            }
            else
            {
                DicConsole.DebugWriteLine("Device-Info command", "PCMCIA CIS returned no tuples");
            }
        }
Exemplo n.º 12
0
        public frmMain(bool debug, bool verbose)
        {
            XamlReader.Load(this);

            lblError  = new Label();
            grdFiles  = new GridView();
            nullImage = null;

            ConsoleHandler.Init();
            ConsoleHandler.Debug   = debug;
            ConsoleHandler.Verbose = verbose;

            treeImagesItems = new TreeGridItemCollection();

            treeImages.Columns.Add(new GridColumn
            {
                HeaderText = "Name", DataCell = new ImageTextCell(0, 1)
            });

            treeImages.AllowMultipleSelection = false;
            treeImages.ShowHeader             = false;
            treeImages.DataStore              = treeImagesItems;

            // TODO: SVG
            imagesIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.inode-directory.png"));

            devicesIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.computer.png"));

            hardDiskIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.drive-harddisk.png"));

            opticalIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.drive-optical.png"));

            usbIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.drive-removable-media-usb.png"));

            removableIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.drive-removable-media.png"));

            sdIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.media-flash-sd-mmc.png"));

            tapeIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.media-tape.png"));

            ejectIcon =
                new Bitmap(ResourceHandler.
                               GetResourceStream("DiscImageChef.Gui.Assets.Icons.oxygen._32x32.media-eject.png"));

            imagesRoot = new TreeGridItem
            {
                Values = new object[]
                {
                    imagesIcon, "Images"
                }
            };

            devicesRoot = new TreeGridItem
            {
                Values = new object[]
                {
                    devicesIcon, "Devices"
                }
            };

            treeImagesItems.Add(imagesRoot);
            treeImagesItems.Add(devicesRoot);

            placeholderItem = new TreeGridItem
            {
                Values = new object[]
                {
                    nullImage, "You should not be seeing this"
                }
            };

            Closing += OnClosing;

            treeImagesMenu         =  new ContextMenu();
            treeImagesMenu.Opening += OnTreeImagesMenuOpening;
            treeImages.ContextMenu =  treeImagesMenu;
        }