Пример #1
0
        public SaveResult AddFileWiz(out ProjectFile file)
        {
            file = null;

            FileAddWizard faw = new FileAddWizard(project);

            if (faw.ShowDialog() == DialogResult.OK)
            {
                if (faw.CreatedFile != null)
                {
                    file = faw.CreatedFile;
                    PopulateList();
                    return(SaveResult.Successful);
                }
                else
                {
                    return(SaveResult.Failed);
                }
            }
            else
            {
                return(SaveResult.Cancelled);
            }
        }
Пример #2
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();
        }
Пример #3
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();
        }
Пример #4
0
        public SaveResult AddFileWiz(out ProjectFile file)
        {
            file = null;

            FileAddWizard faw = new FileAddWizard(project);
            if (faw.ShowDialog() == DialogResult.OK)
            {
                if (faw.CreatedFile != null)
                {
                    file = faw.CreatedFile;
                    PopulateList();
                    return SaveResult.Successful;
                }
                else
                {
                    return SaveResult.Failed;
                }
            }
            else
                return SaveResult.Cancelled;
        }