Пример #1
0
        private static SourcecodeDocument OpenLSTDocument(Window owner, ICSharpCode.AvalonEdit.TextEditor handler, string FileName)
        {
            try
            {
                string s = PICProgramLoader.LoadSourceCodeFromText(FileName);

                if (s == null)
                {
                    return(null);
                }

                string FileNameSrc = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), System.IO.Path.GetFileNameWithoutExtension(FileName) + ".src");

                if (File.Exists(FileNameSrc))
                {
                    if (MessageBox.Show("File \r\n" + FileNameSrc + "\r\nalready exists. Override ?", "Overwrite?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                    {
                        return(null);
                    }
                }

                File.WriteAllText(FileNameSrc, s, Encoding.Default);

                return(new SourcecodeDocument(owner, handler, s, FileNameSrc));
            }
            catch (IOException)
            {
                MessageBox.Show("Error: Could not load File.");
                return(null);
            }
        }
Пример #2
0
        private void CompileExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (!sc_document.Save())
            {
                return;
            }

            string resultPath = Path.Combine(Path.GetDirectoryName(sc_document.Path), Path.GetFileNameWithoutExtension(sc_document.Path) + ".lst");

            if (File.Exists(resultPath))
            {
                File.Delete(resultPath);
            }

            Thread.Sleep(350);

            Process proc = new Process()
            {
                StartInfo = new ProcessStartInfo(@"Compiler\il_ass16.exe", '"' + sc_document.Path + '"')
            };

            proc.Start();
            proc.WaitForExit();

            if (File.Exists(resultPath))
            {
                var cmds = PICProgramLoader.LoadFromFile(resultPath);

                if (cmds == null)
                {
                    MessageBox.Show("Error while reading compiled file.");
                    sc_document.MakeDirty();
                    return;
                }

                controller = new PICController(cmds, getSimuSpeedFromComboBox());
                controller.RaiseCompleteEventResetChain();
                stackList.Reset();
                IconBar.Reset();
            }
        }
Пример #3
0
        private void OpenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (controller != null && (controller.Mode == PICControllerMode.WAITING || controller.Mode == PICControllerMode.FINISHED))
            {
                controller = null;
            }

            bool isLST;

            sc_document.AskSaveIfDirty();

            sc_document = SourcecodeDocument.OpenNew(this, txtCode, out isLST) ?? sc_document;

            if (isLST)
            {
                if (!sc_document.Save())
                {
                    return;
                }

                string resultPath = Path.Combine(Path.GetDirectoryName(sc_document.Path), Path.GetFileNameWithoutExtension(sc_document.Path) + ".lst");

                if (File.Exists(resultPath))
                {
                    var cmds = PICProgramLoader.LoadFromFile(resultPath);

                    if (cmds == null)
                    {
                        MessageBox.Show("Error while reading compiled file.");
                        sc_document.MakeDirty();
                        return;
                    }

                    controller = new PICController(cmds, getSimuSpeedFromComboBox());
                    controller.RaiseCompleteEventResetChain();
                    stackList.Reset();
                    IconBar.Reset();
                }
            }
        }