Esempio n. 1
0
        public static WorkingFolder FromFile(string filename, string directory)
        {
            XmlSerializer ser = new XmlSerializer(typeof(WorkingFolder));

            FileStream fs     = new FileStream(filename, FileMode.Open);
            XmlReader  reader = XmlReader.Create(fs);

            WorkingFolder cfg = (WorkingFolder)ser.Deserialize(reader);

            cfg.Path = new DirectoryInfo(directory).Parent.Parent.FullName;

            cfg.PreferedToCompile.Path = PlatformSpecific.CombinePath(cfg.Path, cfg.PreferedToCompile.Path);
            cfg.CompileConfigPath      = PlatformSpecific.CombinePath(cfg.Path, cfg.CompileConfigPath);
            cfg.UserConfigPath         = PlatformSpecific.CombinePath(cfg.Path, cfg.UserConfigPath);

            fs.Close();
            return(cfg);
        }
Esempio n. 2
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            Point    pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
            FileNode destinationNode = ((TreeView)sender).GetNodeAt(pt) as FileNode;
            FileNode sourceNode      = (FileNode)e.Data.GetData(typeof(FileNode));

            if (destinationNode == null)
            {
                destinationNode = ((TreeView)sender).Nodes[0] as FileNode;                 //root node
            }
            if (!destinationNode.IsDir)
            {
                MessageBox.Show("You can move files/dirs only in directories");
                return;
            }

            string newPath = PlatformSpecific.CombinePath(destinationNode.AbsolutePath, Path.GetFileName(sourceNode.AbsolutePath));

            if (!sourceNode.IsDir)
            {
                if (File.Exists(newPath))
                {
                    MessageBox.Show("File already exists");
                    return;
                }

                foreach (TextEditor editor in tabControl1.TabPages)
                {
                    if (editor.Path == sourceNode.AbsolutePath)
                    {
                        if (!editor.Close())
                        {
                            return;
                        }

                        UpdateOpenedTabs();
                    }
                }

                try
                {
                    File.Move(sourceNode.AbsolutePath, newPath);
                }
                catch
                {
                    MessageBox.Show("Unable to rename file");
                    return;
                }

                workingFolder.SetTreeView(treeView1);
                treeView1.ExpandAll();
            }
            else
            {
                if (Directory.Exists(newPath))
                {
                    MessageBox.Show("Directory already exists");
                    return;
                }

                try
                {
                    Directory.Move(sourceNode.AbsolutePath, newPath);
                }
                catch
                {
                    MessageBox.Show("Unable to rename dir");
                    return;
                }

                workingFolder.SetTreeView(treeView1);
                treeView1.ExpandAll();
            }
        }
Esempio n. 3
0
 public void Save()
 {
     ToFile(PlatformSpecific.CombinePath(Path, MainConfigPostfix), this);
 }
Esempio n. 4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Self = this;

            tabControl1_SizeChanged(null, null);
            string configName = "";

            if (File.Exists("directory.txt"))
            {
                configName = File.ReadAllText("directory.txt");
            }

            if (!Directory.Exists(configName))
            {
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    configName =
                        PlatformSpecific.CombinePath(folderBrowserDialog1.SelectedPath, WorkingFolder.MainConfigPostfix);
                    string compileConfigFileName =
                        PlatformSpecific.CombinePath(folderBrowserDialog1.SelectedPath, WorkingFolder.CompileConfigPostfix);
                    string userConfigFileName =
                        PlatformSpecific.CombinePath(folderBrowserDialog1.SelectedPath, WorkingFolder.UserConfigPostfix);

                    Directory.CreateDirectory(PlatformSpecific.CombinePath(folderBrowserDialog1.SelectedPath, WorkingFolder.IdeDirPostfix));

                    workingFolder = new WorkingFolder()
                    {
                        CompileConfigPath = compileConfigFileName,
                        UserConfigPath    = userConfigFileName,
                        Path = folderBrowserDialog1.SelectedPath,
                        PreferedToCompile = new SourceFile("", "")
                    };

                    WorkingFolder.ToFile(configName, workingFolder);
                    File.WriteAllText("directory.txt", folderBrowserDialog1.SelectedPath);
                }
                else
                {
                    Close();
                    return;
                }
            }
            else
            {
                configName =
                    PlatformSpecific.CombinePath(configName, WorkingFolder.MainConfigPostfix);
                if (File.Exists(configName))
                {
                    workingFolder = WorkingFolder.FromFile(configName, configName);
                }
                else
                {
                    workingFolder = new WorkingFolder()
                    {
                        CompileConfigPath =
                            PlatformSpecific.CombinePath(new FileInfo(configName).DirectoryName, WorkingFolder.CompileConfigPostfix),
                        UserConfigPath =
                            PlatformSpecific.CombinePath(new FileInfo(configName).DirectoryName, WorkingFolder.UserConfigPostfix),
                        Path = new FileInfo(configName).Directory.Parent.FullName,
                    };
                    WorkingFolder.ToFile(configName, workingFolder);
                }
            }

            if (File.Exists(workingFolder.UserConfigPath))
            {
                workingFolder.UserConfig = UserConfig.FromFile(workingFolder.UserConfigPath, workingFolder.Path);

                Size = workingFolder.UserConfig.WindowSize;
                splitContainer_main.SplitterDistance   = workingFolder.UserConfig.MainSplitterDistance;
                splitContainer_editor.SplitterDistance = workingFolder.UserConfig.EditorSplitterDistance;

                if (workingFolder.UserConfig.WindowPosition.X == -32000)
                {
                    WindowState = FormWindowState.Minimized;
                }
                else
                {
                    Left = workingFolder.UserConfig.WindowPosition.X;
                    Top  = workingFolder.UserConfig.WindowPosition.Y;
                }
            }
            else
            {
                workingFolder.UserConfig = new UserConfig()
                {
                    EditorSplitterDistance = splitContainer_editor.SplitterDistance,
                    MainSplitterDistance   = splitContainer_main.SplitterDistance,
                    OpenedTabs             = new List <string>(),
                    OutputType             = OutputType.Hex,
                    SelectedTab            = -1,
                    WindowPosition         = new Point(Left, Top),
                    WindowSize             = Size
                };
                UserConfig.ToFile(workingFolder.UserConfigPath, workingFolder.UserConfig);
            }

            if (File.Exists(workingFolder.CompileConfigPath))
            {
                workingFolder.CompileConfig          = CompileConfig.FromFile(workingFolder.CompileConfigPath);
                workingFolder.CompileConfig.FileName = workingFolder.CompileConfigPath;
            }
            else
            {
                workingFolder.CompileConfig = new CompileConfig()
                {
                    FileName = workingFolder.CompileConfigPath
                };
                CompileConfig.ToFile(workingFolder.CompileConfigPath, workingFolder.CompileConfig);
            }

            Machine = new HASMMachine(
                (uint)workingFolder.CompileConfig.RAM,
                (uint)workingFolder.CompileConfig.EEPROM,
                (uint)workingFolder.CompileConfig.Flash,
                workingFolder.CompileConfig.Base)
            {
                BannedFeatures     = workingFolder.CompileConfig.BannedFeatures,
                UserDefinedDefines = workingFolder.CompileConfig.Defines
                                     .FindAll(p => !string.IsNullOrEmpty(p.Name))
                                     .Select(p => new HASMLib.Parser.SyntaxTokens.Preprocessor.Define(p.Name, new HASMLib.Parser.SyntaxTokens.Preprocessor.StringGroup(p.Value)))
                                     .ToList()
            };
            Machine.SetRegisters(workingFolder.CompileConfig.RegisterNameFormat, (uint)workingFolder.CompileConfig.RegisterCount);
            foreach (var path in workingFolder.CompileConfig.IncludePaths)
            {
                string value   = path.Split(',')[0];
                string pattern = path.Split(',')[1];

                if (Directory.Exists(value))
                {
                    Machine.Cache.AddFileNames(value, pattern);
                }

                else
                {
                    value = PlatformSpecific.CombinePath(workingFolder.Path, value);
                    if (Directory.Exists(value))
                    {
                        Machine.Cache.AddFileNames(value, pattern);
                    }

                    else
                    {
                        MessageBox.Show($"Unable to directory file {value}",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }
                }
            }
            RebuildCache();
            if (workingFolder.UserConfig.OpenedTabs != null)
            {
                foreach (string path in workingFolder.UserConfig.OpenedTabs)
                {
                    AddTab(path);
                }
            }

            workingFolder.SetTreeView(treeView1);
            treeView1.ExpandAll();

            toolStripComboBox1.Items.Clear();
            toolStripComboBox1.Items.AddRange(workingFolder.SourceFiles.Select(p => (object)p).ToArray());

            toolStripComboBox1.SelectedItem = workingFolder.PreferedToCompile;

            tabControl1.Enabled       = true;
            tabControl1.SelectedIndex = workingFolder.UserConfig.SelectedTab;

            switch (workingFolder.UserConfig.OutputType)
            {
            case OutputType.Hex:
                hexOutputToolStripMenuItem.Checked = true;
                break;

            case OutputType.Dec:
                decOutputToolStripMenuItem.Checked = true;
                break;

            case OutputType.Char:
                charOutputToolStripMenuItem.Checked = true;
                break;

            default:
                break;
            }
            outputType = workingFolder.UserConfig.OutputType;

            Text = $"HASM Editor { (tabControl1.SelectedTab == null ? "" : " - " + (tabControl1.SelectedTab as TextEditor).Path.NormalizePath())}";
        }