public void RemoveNode(TreeNode node)
        {
            string fileName = node.Text;

            ProjectFile f = null;

            if (project.FileList.TryGetValue(fileName.ToLowerInvariant(), out f))
            {
                project.FileList.Remove(fileName.ToLowerInvariant());
                if (f.BackupExists)
                {
                    try
                    {
                        File.Delete(f.BackupPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Could not delete backup of " + f.FileName + " due to error: " + ex.Message);
                    }
                }
            }

            EditorPanel editor;

            if (editorList.TryGetValue(fileName.ToLowerInvariant(), out editor))
            {
                editor.Close();
                editorList.Remove(fileName.ToLowerInvariant());
            }

            node.Remove();

            if (f != null)
            {
                if (f.Exists)
                {
                    if (MessageBox.Show("'" + f.FileName + "' has been removed from the project. Do you want to delete '" + f.FileName + "' permanently?", "Delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        try
                        {
                            File.Delete(f.FileAbsPath);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Could not delete '" + f.FileAbsPath + "', " + ex.Message);
                        }
                    }
                }
            }

            if (project.Save() == SaveResult.Failed)
            {
                MessageBox.Show("Error saving project");
            }
        }
Beispiel #2
0
        private void mbtnSaveConfigAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "AVR Project (*.avrproj)|*.avrproj";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (myProject.Save(sfd.FileName) == false)
                {
                    MessageBox.Show("Error While Saving Project Configuration File");
                }
            }
        }
Beispiel #3
0
 private SaveResult SaveProj()
 {
     if (string.IsNullOrEmpty(myProj.FilePath))
     {
         return(SaveProjAs());
     }
     else
     {
         if (myProj.Save(myProj.FilePath))
         {
             return(SaveResult.Successful);
         }
         else
         {
             MessageBox.Show("Save Failed");
             return(SaveResult.Failed);
         }
     }
 }
Beispiel #4
0
        private void btnSaveAndClose_Click(object sender, EventArgs e)
        {
            ApplyChanges();
            closingViaButtons = true;

            if (project.Save() == SaveResult.Failed)
            {
                MessageBox.Show("Error saving project");
            }
            else
            {
                this.Close();
            }
        }
        public bool SaveAll()
        {
            bool success = true;

            myProject.Save();
            foreach (KeyValuePair <string, FileEditorTab> i in myListOfEditors)
            {
                if (i.Value.Save() == false)
                {
                    success = false;
                }
            }
            return(success);
        }
Beispiel #6
0
        private void btnImportAPS_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "AVR Studio Project (*.aps)|*.aps";

            if (string.IsNullOrEmpty(SettingsManagement.FavFolder) == false)
            {
                ofd.InitialDirectory = SettingsManagement.FavFolder + Path.DirectorySeparatorChar;
            }

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (project.ImportAPS(ofd.FileName))
                {
                    MessageBox.Show("Import was Successful" + Environment.NewLine + "Please Save It");
                    SaveResult res = project.Save();
                    if (res == SaveResult.Failed)
                    {
                        MessageBox.Show("Error During Save");
                    }
                    else if (res == SaveResult.Cancelled)
                    {
                        project.IsReady = false;
                    }
                    else
                    {
                        SettingsManagement.AddFileAsMostRecent(project.FilePath);
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Error During Import");
                }
            }
        }
Beispiel #7
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string iniFilename = txtInitialFilename.Text.Trim();
            bool   hasIniFile  = !string.IsNullOrEmpty(iniFilename);

            hasIniFile = false;
            string projFilename = txtProjName.Text.Trim();

            if (string.IsNullOrEmpty(projFilename))
            {
                MessageBox.Show("The project name can't be blank");
                return;
            }

            char[] forbidChars = Path.GetInvalidFileNameChars();
            foreach (char c in forbidChars)
            {
                if (hasIniFile && iniFilename.Contains(c))
                {
                    MessageBox.Show("Illegal Character in Initial File Name");
                    return;
                }

                if (projFilename.Contains(c))
                {
                    MessageBox.Show("Illegal Character in Project File Name");
                    return;
                }
            }

            if (hasIniFile)
            {
                if (iniFilename.Contains('/') || iniFilename.Contains('\\') || iniFilename.Contains(Path.DirectorySeparatorChar) || iniFilename.Contains(Path.AltDirectorySeparatorChar))
                {
                    MessageBox.Show("Illegal Character in Initial File Name");
                    return;
                }

                if (iniFilename.Contains('.') || iniFilename.Contains(' ') || iniFilename.Contains('\t'))
                {
                    MessageBox.Show("No Spaces or Dots are Allowed in Initial File Name");
                    return;
                }
            }

            if (projFilename.Contains('/') || projFilename.Contains('\\') || projFilename.Contains(Path.DirectorySeparatorChar) || projFilename.Contains(Path.AltDirectorySeparatorChar))
            {
                MessageBox.Show("Illegal Character in Project File Name");
                return;
            }

            if (projFilename.Contains('.'))
            {
                MessageBox.Show("No Dots are Allowed in Project File Name");
                return;
            }

            string folderPath = Program.CleanFilePath(txtFolderPath.Text);

            if (Program.MakeSurePathExists(folderPath) == false)
            //if (Directory.Exists(folderPath))
            {
                MessageBox.Show("Error Creating Folder");
                //MessageBox.Show("Error: Folder Invalid");
                return;
            }

            string projFilePath = folderPath + Path.DirectorySeparatorChar + projFilename + ".avrproj";

            project.FilePath = projFilePath;

            string ext = "c";

            if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("C++"))
            {
                ext = "cpp";
            }
            else if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("C"))
            {
                ext = "c";
            }
            else if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("Arduino"))
            {
                ext = "pde";
            }

            string iniFilePath = folderPath + Path.DirectorySeparatorChar + iniFilename + "." + ext;

            if (File.Exists(projFilePath))
            {
                if (MessageBox.Show("Project File Already Exists at the Location, Overwrite it?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            bool merge = false;

            if (hasIniFile && File.Exists(iniFilePath))
            {
                if (MessageBox.Show("Initial File Already Exists at the Location, Merge it with your project?", "Merge File?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    merge = true;
                }
                else if (MessageBox.Show("Maybe you'd rather overwrite it with a blank file?", "Overwrite File?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            if (hasIniFile)
            {
                if (merge == false)
                {
                    try
                    {
                        StreamWriter writer = new StreamWriter(iniFilePath);
                        if (ext == "pde")
                        {
                            writer.Write(FileTemplate.CreateFile(iniFilename + "." + ext, projFilename, "initialpde.txt"));
                        }
                        else
                        {
                            writer.Write(FileTemplate.CreateFile(iniFilename + "." + ext, projFilename, "initialmain.txt"));
                        }
                        writer.WriteLine();
                        writer.Close();
                    }
                    catch (Exception ex)
                    {
                        ErrorReportWindow.Show(ex, "Error while creating initial file");
                    }
                }

                ProjectFile newFile = new ProjectFile(iniFilePath, project);
                newFile.IsOpen = true;
                project.FileList.Add(newFile.FileName.ToLowerInvariant(), newFile);
            }

            ProjTemplate.ApplyTemplate((string)dropTemplates.Items[dropTemplates.SelectedIndex], project);

            project.FilePath = projFilePath;

            FileAddWizard faw = new FileAddWizard(project);

            faw.ShowDialog();

            if (project.Save(projFilePath) == false)
            {
                MessageBox.Show("Error While Saving Project");
            }
            else
            {
                if (project.Open(projFilePath) == false)
                {
                    MessageBox.Show("Error While Opening Project");
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        private void btnClone_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtPath.Text))
            {
                MessageBox.Show("The path cannot be empty");
                return;
            }

            if (Program.MakeSurePathExists(txtPath.Text))
            {
                string targetDir = txtPath.Text + Path.DirectorySeparatorChar + project.FileNameNoExt;
                if (Program.MakeSurePathExists(targetDir))
                {
                    AVRProject newProject = new AVRProject();
                    newProject = project.CopyProperties(newProject);
                    newProject.FileList.Clear();
                    newProject.FilePath = targetDir + Path.DirectorySeparatorChar + project.FileNameNoExt + ".avrproj";
                    foreach (KeyValuePair <string, ProjectFile> file in project.FileList)
                    {
                        try
                        {
                            string nfpath;
                            if (file.Value.FileRelProjPath.StartsWith(".."))
                            {
                                if (radCopyAll.Checked)
                                {
                                    string extDir = targetDir + Path.DirectorySeparatorChar + "external_files";
                                    nfpath = extDir + Path.DirectorySeparatorChar + file.Value.FileName;
                                }
                                else
                                {
                                    nfpath = file.Value.FileAbsPath;
                                }
                            }
                            else
                            {
                                nfpath = targetDir + Path.DirectorySeparatorChar + file.Value.FileRelProjPath;
                            }

                            ProjectFile npf = new ProjectFile(nfpath, newProject);
                            npf.Options   = file.Value.Options;
                            npf.ToCompile = file.Value.ToCompile;

                            if (file.Value.FileAbsPath != nfpath)
                            {
                                if (Program.MakeSurePathExists(npf.FileDir))
                                {
                                    try
                                    {
                                        File.Copy(file.Value.FileAbsPath, nfpath, true);
                                        newProject.FileList.Add(file.Key, npf);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("Error while copying '" + file.Key + "' to '" + nfpath + "' : " + ex.Message);
                                        return;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Error while creating '" + npf.FileDir + "'");
                                    return;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error during the cloning process: " + ex.Message);
                            return;
                        }
                    }

                    try
                    {
                        if (chkCopyUnmanaged.Checked)
                        {
                            Program.CopyAll(new DirectoryInfo(project.DirPath), new DirectoryInfo(targetDir));
                        }

                        if (newProject.Save() == SaveResult.Successful)
                        {
                            if (chkOpenAfterClone.Checked)
                            {
                                try
                                {
                                    System.Diagnostics.Process.Start(newProject.DirPath);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Could not open folder: " + ex.Message);
                                }
                            }

                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("An error occured, the project XML (.avrproj) file did not save.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error during the cloning process: " + ex.Message);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("The path cannot be found or created");
                    return;
                }
            }
            else
            {
                MessageBox.Show("The path cannot be found or created");
                return;
            }

            this.Close();
        }
        private void btnClone_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtPath.Text))
            {
                MessageBox.Show("The path cannot be empty");
                return;
            }

            if (Program.MakeSurePathExists(txtPath.Text))
            {
                string targetDir = txtPath.Text + Path.DirectorySeparatorChar + project.FileNameNoExt;
                if (Program.MakeSurePathExists(targetDir))
                {
                    AVRProject newProject = new AVRProject();
                    newProject = project.CopyProperties(newProject);
                    newProject.FileList.Clear();
                    newProject.FilePath = targetDir + Path.DirectorySeparatorChar + project.FileNameNoExt + ".avrproj";
                    foreach (KeyValuePair<string, ProjectFile> file in project.FileList)
                    {
                        try
                        {
                            string nfpath;
                            if (file.Value.FileRelProjPath.StartsWith(".."))
                            {
                                
                                if (radCopyAll.Checked)
                                {
                                    string extDir = targetDir + Path.DirectorySeparatorChar + "external_files";
                                    nfpath = extDir + Path.DirectorySeparatorChar + file.Value.FileName;
                                }
                                else
                                {
                                    nfpath = file.Value.FileAbsPath;
                                }
                            }
                            else
                            {
                                nfpath = targetDir + Path.DirectorySeparatorChar + file.Value.FileRelProjPath;
                            }

                            ProjectFile npf = new ProjectFile(nfpath, newProject);
                            npf.Options = file.Value.Options;
                            npf.ToCompile = file.Value.ToCompile;

                            if (file.Value.FileAbsPath != nfpath)
                            {
                                if (Program.MakeSurePathExists(npf.FileDir))
                                {
                                    try
                                    {
                                        File.Copy(file.Value.FileAbsPath, nfpath, true);
                                        newProject.FileList.Add(file.Key, npf);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("Error while copying '" + file.Key + "' to '" + nfpath + "' : " + ex.Message);
                                        return;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Error while creating '" + npf.FileDir + "'");
                                    return;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error during the cloning process: " + ex.Message);
                            return;
                        }
                    }

                    try
                    {
                        if (chkCopyUnmanaged.Checked)
                        {
                            Program.CopyAll(new DirectoryInfo(project.DirPath), new DirectoryInfo(targetDir));
                        }

                        if (newProject.Save() == SaveResult.Successful)
                        {
                            if (chkOpenAfterClone.Checked)
                            {
                                try
                                {
                                    System.Diagnostics.Process.Start(newProject.DirPath);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Could not open folder: " + ex.Message);
                                }
                            }

                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("An error occured, the project XML (.avrproj) file did not save.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error during the cloning process: " + ex.Message);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("The path cannot be found or created");
                    return;
                }
            }
            else
            {
                MessageBox.Show("The path cannot be found or created");
                return;
            }

            this.Close();
        }
Beispiel #10
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string f = txtFileName.Text.Trim();

            if (string.IsNullOrEmpty(f))
            {
                MessageBox.Show("File name must not be blank");
                return;
            }

            string fileName;

            if (f.EndsWith("."))
            {
                fileName = f + this.SelectedExtension.TrimStart('.');
            }
            else if (f.Contains("."))
            {
                fileName = f;
            }
            else
            {
                fileName = f + "." + this.SelectedExtension.TrimStart('.');
            }

            if (
                fileName.Contains(" ") ||
                fileName.Contains("\t") ||
                fileName.Contains("\r") ||
                fileName.Contains("\n") ||
                fileName.Contains("\0") ||
                fileName.Contains("\\") ||
                fileName.Contains("/")
                )
            {
                MessageBox.Show("Invalid Character in File Name");
                return;
            }

            foreach (char c in Path.GetInvalidFileNameChars())
            {
                if (fileName.Contains(char.ToString(c)))
                {
                    MessageBox.Show("Invalid Character '" + c + "' in File Name");
                    return;
                }
            }

            string fileAbsPath = txtDirLoc.Text + fileName;

            foreach (char c in Path.GetInvalidPathChars())
            {
                if (fileAbsPath.Contains(char.ToString(c)))
                {
                    MessageBox.Show("Invalid Character '" + c + "' in File Path");
                    return;
                }
            }

            string fileNameL = fileName.ToLowerInvariant();

            if (project.FileList.ContainsKey(fileNameL))
            {
                if (project.FileList[fileNameL].Exists)
                {
                    MessageBox.Show("File already exists in the project");
                    return;
                }
            }
            else
            {
                project.FileList.Add(fileNameL, new ProjectFile(fileAbsPath, project));
            }

            if (project.FileList[fileNameL].Exists == false)
            {
                if (((string)dropTemplates.Items[dropTemplates.SelectedIndex]) != "none")
                {
                    try
                    {
                        File.WriteAllText(fileAbsPath, FileTemplate.CreateFile(fileName, project.FileNameNoExt, ((string)dropTemplates.Items[dropTemplates.SelectedIndex]) + ".txt"));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error writing file from template, " + ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        File.WriteAllText(fileAbsPath, "");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error creating file, " + ex.Message);
                    }
                }
            }

            createdFile = project.FileList[fileNameL];

            if (project.FileList.Count == 1)
            {
                project.FileList[fileNameL].IsOpen = true;
            }

            if (project.Save() == SaveResult.Failed)
            {
                MessageBox.Show("Error saving project");
            }

            SettingsManagement.LastFileExt = createdFile.FileExt;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }