Пример #1
0
        /// <summary>
        /// Opens a file.
        /// </summary>
        /// <param name="path">the file name of the file to open</param>
        void Core_OpenFile(string path)
        {
            if (!File.Exists(path))
            {
                Program.ShowMessage("The file does not exist.");
                return;
            }

            try
            {
                FileByteProvider file;
                try
                {
                    // try to open in write mode
                    file                = new FileByteProvider(path);
                    file.Changed       += new EventHandler(HexBox_ByteProvider_Changed);
                    file.LengthChanged += new EventHandler(HexBox_ByteProvider_LengthChanged);
                }
                catch (IOException) // write mode failed
                {
                    try
                    {
                        // try to open in read-only mode
                        file = new FileByteProvider(path, true);
                        if (Program.ShowQuestion("This file can only be opened as read-only. Proceed ?") == DialogResult.No)
                        {
                            file.Dispose();
                            return;
                        }
                    }
                    catch (IOException ex) // read-only also failed
                    {
                        // file cannot be opened
                        Program.ShowError("The attempt to open the file has failed.", ex);
                        return;
                    }
                }

                Core_CreateTabPage(file, path);

                Menu_File_RecentFiles.AddFile(path);
            }
            catch (Exception ex)
            {
                Program.ShowError(ex);
                return;
            }
        }
Пример #2
0
        private void buttonHex_Click(object sender, EventArgs e)
        {
            if (byteProvider != null)
            {
                byteProvider.Dispose();
            }
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter = "Hex文件|*.hex|所有文件|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                File.Copy(fileDialog.FileName, "./temp/" + Path.GetFileName(fileDialog.FileName), true);
                byteProvider           = new FileByteProvider("./temp/" + Path.GetFileName(fileDialog.FileName));
                hexBoxPRG.ByteProvider = byteProvider;
                textBoxHex.Text        = fileDialog.FileName;
                FileInfo fileInfo = new FileInfo("./temp/" + Path.GetFileName(fileDialog.FileName));
                textBoxHexSize.Text = (fileInfo.Length / 1024).ToString() + "KB";
            }
        }