Beispiel #1
0
        public MainWindow(DllViewerContext context = null)
        {
            InitializeComponent();
            Context = context ?? new DllViewerContext();
            ResolveAssemblies(Context);

            _selectedItemChanging  = true;
            this.DataContext       = Context;
            DataGrid1.ItemsSource  = Context.Assemblies;
            DataGrid1.SelectedItem = Context.SelectedAssembly;
            _selectedItemChanging  = false;

            DataGrid1.UpdateLayout();
            DataGrid1.ScrollIntoView(DataGrid1.SelectedItem);
        }
Beispiel #2
0
        private static void ResolveAssemblies(DllViewerContext context)
        {
            var path = context.CommandLine.FirstOrDefault();

            if (path == null)
            {
                var thisExe = Assembly.GetExecutingAssembly();
                path = thisExe.Location;
            }

            string directoryPath = null;
            string selectedPath  = null;

            if (Directory.Exists(path))
            {
                directoryPath = path;
            }
            else if (File.Exists(path))
            {
                directoryPath = Path.GetDirectoryName(path);
                selectedPath  = path;
            }

            var assemblies = directoryPath == null
                ? new AssemblyInfo[0]
                : Directory.GetFiles(directoryPath, "*.exe")
                             .Union(
                Directory.GetFiles(directoryPath, "*.dll"))
                             .Select(p => new AssemblyInfo(p))
                             .ToArray();

            var selectedFileName = Path.GetFileName(selectedPath);
            var selectedAssembly = selectedPath == null
                ? assemblies.FirstOrDefault()
                : assemblies.FirstOrDefault(a => IsFileNameEqual(a.Location, selectedFileName)) ?? assemblies.FirstOrDefault();

            for (var i = 0; i < assemblies.Length; i++)
            {
                assemblies[i].Id = i + 1;
            }

            context.Location = assemblies.Length == 0 ? "No assembly selected." : directoryPath;

            context.Assemblies       = assemblies;
            context.SelectedAssembly = selectedAssembly;
        }