📄 vbproject.cs
字号:
// VBProject.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel;
using System.Xml;
using SharpDevelop.Internal.Project;
namespace VBDefinition {
/// <summary>
/// This class describes a C Sharp project and it compilation options.
/// </summary>
public class VBProject : ISdProject
{
string basedirectory = "C:\\";
string projectname = "New Project";
string workingdir = "C:\\";
string outputdir = "C:\\";
string outputassembly = "out";
string description = "";
ArrayList directories = new ArrayList();
ArrayList files = new ArrayList();
ArrayList references = new ArrayList();
ArrayList modules = new ArrayList();
VBProjectCompilerParameters compilerparameters = new VBProjectCompilerParameters();
public ArrayList Directories {
get {
return directories;
}
set {
directories = value;
}
}
public object CompilerParameters {
get {
return compilerparameters;
}
}
public string BaseDirectory {
get {
return basedirectory;
}
}
public string Description {
get {
return description;
}
set {
description = value;
}
}
public string Name {
get {
return projectname;
}
set {
projectname = value;
}
}
public string WorkingDirectory {
get {
if (workingdir.Length > 0 && workingdir[workingdir.Length - 1] == '\\')
workingdir = workingdir.Substring(0, workingdir.Length - 1);
return workingdir;
}
set {
workingdir = value;
}
}
public string OutputDirectory {
get {
return outputdir;
}
set {
outputdir = value;
}
}
public string OutputAssembly {
get {
return outputassembly;
}
set {
outputassembly = Path.ChangeExtension(value, "");
if (outputassembly.Length > 0)
outputassembly = outputassembly.Substring(0, outputassembly.Length - 1);
}
}
public ArrayList Files {
get {
return files;
}
set {
files = value;
}
}
public ArrayList References {
get {
return references;
}
set {
references = value;
}
}
public ArrayList Modules {
get {
return modules;
}
set {
modules = value;
}
}
public string ProjectType {
get {
return "VBNET";
}
}
public Hashtable Icons {
get {
return null;
}
}
public VBProject()
{}
static string MakeRelative(string what, string path)
{
if (what.Length >= path.Length && what.Substring(0, path.Length) == path)
what = what.Substring(path.Length);
return what;
}
static string MakeAbsolute(string what, string path)
{
if (what.Length > 0 && what[0] == '\\')
return path + what;
return what;
}
public bool IsFileInProject(string filename)
{
foreach (string file in files) {
if (file == filename)
return true;
}
return false;
}
public void LoadProject(string filename)
{
Debug.Assert(File.Exists(filename), "Project.LoadProject : projectfile doesn't exist");
string filepath = Path.GetDirectoryName(filename);
basedirectory = filepath;
XmlDocument doc = new XmlDocument();
doc.Load(filename);
projectname = doc.DocumentElement.Attributes["NAME"].InnerText;
description = doc.DocumentElement.Attributes["DESCRIPTION"].InnerText;
workingdir = MakeAbsolute(doc.DocumentElement.Attributes["DIRECTORY"].InnerText, filepath);
outputassembly = doc.DocumentElement["OUTPUT"].InnerText;
outputdir = MakeAbsolute(doc.DocumentElement["OUTPUT"].Attributes["DIRECTORY"].InnerText, filepath);
XmlNodeList nodes = doc.DocumentElement["REFERENCES"].ChildNodes;
references.Clear();
foreach (XmlNode node in nodes)
references.Add(MakeAbsolute(node.InnerText, filepath));
if (doc.DocumentElement["DIRECTORIES"] != null) {
nodes = doc.DocumentElement["DIRECTORIES"].ChildNodes;
directories.Clear();
foreach (XmlNode node in nodes) {
directories.Add(MakeAbsolute(node.InnerText, filepath));
}
}
nodes = doc.DocumentElement["FILES"].ChildNodes;
files.Clear();
foreach (XmlNode node in nodes) {
files.Add(MakeAbsolute(node.InnerText, filepath));
}
nodes = doc.DocumentElement["MODULES"].ChildNodes;
modules.Clear();
foreach (XmlNode node in nodes)
modules.Add(MakeAbsolute(node.InnerText, filepath));
compilerparameters = new VBProjectCompilerParameters(doc.DocumentElement["COMPILERPARAMETERS"]);
}
public void SaveProject(string filename)
{
string filepath = Path.GetDirectoryName(filename);
XmlDocument doc = new XmlDocument();
string relpath = MakeRelative(workingdir, filepath);
if (relpath == null || relpath.Length == 0)
relpath = "\\";
doc.LoadXml("<PROJECT NAME=\"" + projectname + "\" DIRECTORY=\"" + relpath + "\" PROJECTTYPE=\"" + ProjectType + "\" DESCRIPTION=\"" + description + "\" />");
// create output node
XmlElement output = doc.CreateElement("OUTPUT");
output.InnerText = outputassembly;
doc.DocumentElement.AppendChild(output);
XmlAttribute outputdirnode = doc.CreateAttribute("DIRECTORY");
relpath = MakeRelative(OutputDirectory, filepath);
if (relpath == null || relpath.Length == 0)
relpath = "\\";
outputdirnode.Value = relpath;
output.Attributes.Append(outputdirnode);
// create reference node
XmlElement refnode = doc.CreateElement("REFERENCES");
doc.DocumentElement.AppendChild(refnode);
foreach (string reference in references) {
XmlElement e = doc.CreateElement("REFERENCE");
e.InnerText = MakeRelative(reference, filepath);
refnode.AppendChild(e);
}
// create directory node
XmlElement directorynode = doc.CreateElement("DIRECTORIES");
doc.DocumentElement.AppendChild(directorynode);
foreach (string dir in directories) {
XmlElement e = doc.CreateElement("DIRECTORY");
e.InnerText = MakeRelative(dir, filepath);
directorynode.AppendChild(e);
}
// create file node
XmlElement filenode = doc.CreateElement("FILES");
doc.DocumentElement.AppendChild(filenode);
foreach (string file in files) {
XmlElement e = doc.CreateElement("FILE");
e.InnerText = MakeRelative(file, filepath);
filenode.AppendChild(e);
}
// modules
XmlElement modulenode = doc.CreateElement("MODULES");
doc.DocumentElement.AppendChild(modulenode);
foreach (string module in modules) {
XmlElement e = doc.CreateElement("MODULE");
e.InnerText = MakeRelative(module, filepath);
modulenode.AppendChild(e);
}
doc.DocumentElement.AppendChild(compilerparameters.ToXmlElement(doc));
doc.Save(filename);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -