コード例 #1
0
        private void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (File.Exists(path))
            {
                MainForm.targetAVMPath = path;

                var bytes = File.ReadAllBytes(path);

                var mapFileName = path.Replace(".avm", ".neomap");

                debugMode      = DebugMode.Assembly;
                sourceLanguage = SourceLanguageKind.Other;

                if (File.Exists(mapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(mapFileName);
                }
                else
                {
                    map = null;
                }

                this.debugger = new NeoDebugger(bytes);
                this.avm_asm  = NeoDisassembler.Disassemble(bytes);

                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;

                    FileName.Text = srcFile;

                    sourceLanguage = LanguageSupport.DetectLanguage(srcFile);

                    debugMode = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                ReloadTextArea();

                StorageLoad();

                UpdateSourceViewMenus();

                shouldReset = true;
            }
        }
コード例 #2
0
        private void ReloadTextArea()
        {
            var keywords = LanguageSupport.GetLanguageKeywords(sourceLanguage);

            if (keywords.Length == 2)
            {
                TextArea.SetKeywords(0, keywords[0]);
                TextArea.SetKeywords(1, keywords[1]);
            }

            TextArea.ReadOnly = false;
            TextArea.Text     = debugContent[debugMode];
            TextArea.ReadOnly = true;
        }
コード例 #3
0
        private void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (File.Exists(path))
            {
                MainForm.targetAVMPath = path;

                this.contractName = Path.GetFileNameWithoutExtension(path);

                this.contractBytecode = File.ReadAllBytes(path);

                var oldMapFileName = path.Replace(".avm", ".neomap");
                var newMapFileName = path.Replace(".avm", ".debug.json");

                debugMode      = DebugMode.Assembly;
                sourceLanguage = SourceLanguageKind.Other;

                if (File.Exists(newMapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(newMapFileName, contractBytecode);

                    this.contractName = map.contractName;
                }
                else
                {
                    if (File.Exists(oldMapFileName))
                    {
                        MessageBox.Show("Warning: The file format of debug map changed. Please recompile your AVM with the latest compiler.");
                    }
                    map = null;
                }

                string abiFilename = path.Replace(".avm", ".abi.json");
                if (File.Exists(abiFilename))
                {
                    abi = new ABI(abiFilename);
                }
                else
                {
                    MessageBox.Show($"Error: {abiFilename} was not found. Please recompile your AVM with the latest compiler.");
                    return;
                }

                this.debugger = null;
                this.avm_asm  = NeoDisassembler.Disassemble(contractBytecode);

                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;

                    if (string.IsNullOrEmpty(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the debug map correct, no file entries.");
                        return;
                    }

                    if (!File.Exists(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the source code, check that this file exists:" + srcFile);
                        return;
                    }

                    FileName.Text = srcFile;

                    sourceLanguage = LanguageSupport.DetectLanguage(srcFile);

                    debugMode = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                ReloadTextArea();

                BlockchainLoad();

                UpdateSourceViewMenus();

                shouldReset = true;

                settings.lastOpenedFile = path;
                settings.Save();
            }
        }