Beispiel #1
0
        public bool LoadFile(string filename)
        {
            // clear some variables
            selectedBin = null;
            modifiedBins.Clear();

            // filename can be any file or a .binmap
            bool isBinmap = false;

            try
            {
                isBinmap = loadBinmapFile(filename);
            }
            catch (Exception e)
            {
                LastError = "Exception while trying to load binmap file: " + e.Message;
                return(false);
            }

            if (isBinmap)
            {
                DataFilename   = Path.Combine(Path.GetDirectoryName(filename), BinmapDataFilename);
                BinmapFilename = filename;
            }
            else
            {
                DataFilename   = filename;
                BinmapFilename = filename + ".binmap";
            }

            if (!File.Exists(DataFilename))
            {
                LastError = "The associated file '" + DataFilename + "' was not found!";
                return(false);
            }

            list.Lock();

            try
            {
                byte[] bytes = File.ReadAllBytes(DataFilename);

                list.Clear();

                int offset = 0;

                foreach (byte b in bytes)
                {
                    Bin item = new Bin(b, offset);
                    list.AddItem(item);
                    offset++;
                }
            }
            catch (Exception e)
            {
                LastError = "Failed to load data: " + e.Message;
                return(false);
            }

            try
            {
                loadBinmapFile(BinmapFilename, true);
            }
            catch (Exception e)
            {
                LastError = "Exception while trying to load binmap file: " + e.Message;
                return(false);
            }

            list.Unlock();
            saveButton.Visible  = list.NumVisible > 0;
            gotoInput.Visible   = saveButton.Visible;
            searchInput.Visible = saveButton.Visible;
            return(true);
        }