Browse Source

Fixed forum-9719: cannot include binary files in project templates.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1563 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
88688e3a01
  1. 17
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  2. 16
      src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs
  3. 2
      src/Main/Base/Project/Src/Internal/Templates/File/ScriptRunner.cs
  4. 14
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs
  5. 2
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

17
src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs

@ -373,7 +373,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -373,7 +373,7 @@ namespace ICSharpCode.SharpDevelop.Gui
return true;
}
public void SaveFile(FileDescriptionTemplate newfile, string content)
public void SaveFile(FileDescriptionTemplate newfile, string content, byte[] binaryContent)
{
string parsedFileName = StringParser.Parse(newfile.Name);
// Parse twice so that tags used in included standard header are parsed
@ -382,9 +382,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -382,9 +382,16 @@ namespace ICSharpCode.SharpDevelop.Gui
parsedFileName = parsedFileName.Substring(1);
if (newfile.IsDependentFile && Path.IsPathRooted(parsedFileName)) {
Directory.CreateDirectory(Path.GetDirectoryName(parsedFileName));
File.WriteAllText(parsedFileName, parsedContent, ParserService.DefaultFileEncoding);
if (binaryContent != null)
File.WriteAllBytes(parsedFileName, binaryContent);
else
File.WriteAllText(parsedFileName, parsedContent, ParserService.DefaultFileEncoding);
ParserService.ParseFile(parsedFileName, parsedContent);
} else {
if (binaryContent != null) {
LoggingService.Warn("binary file was skipped");
return;
}
IWorkbenchWindow window = FileService.NewFile(Path.GetFileName(parsedFileName), StringParser.Parse(newfile.Language), parsedContent);
if (window == null) {
return;
@ -486,7 +493,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -486,7 +493,11 @@ namespace ICSharpCode.SharpDevelop.Gui
ScriptRunner scriptRunner = new ScriptRunner();
foreach (FileDescriptionTemplate newfile in item.Template.FileDescriptionTemplates) {
SaveFile(newfile, scriptRunner.CompileScript(item.Template, newfile));
if (newfile.ContentData != null) {
SaveFile(newfile, null, newfile.ContentData);
} else {
SaveFile(newfile, scriptRunner.CompileScript(item.Template, newfile), null);
}
}
DialogResult = DialogResult.OK;
}

16
src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs

@ -19,7 +19,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -19,7 +19,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
{
string name;
string language;
// Either content or contentData is set, the other is null
string content;
byte[] contentData;
string buildAction;
string copyToOutputDirectory;
string dependentUpon;
@ -42,7 +46,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -42,7 +46,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
if (xml.HasAttribute("src")) {
string fileName = Path.Combine(hintPath, StringParser.Parse(xml.GetAttribute("src")));
try {
content = File.ReadAllText(fileName);
if (xml.HasAttribute("binary") && bool.Parse(xml.GetAttribute("binary"))) {
contentData = File.ReadAllBytes(fileName);
} else {
content = File.ReadAllText(fileName);
}
} catch (Exception e) {
content = "Error reading content from " + fileName + ":\n" + e.ToString();
LoggingService.Warn(content);
@ -95,6 +103,12 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -95,6 +103,12 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
}
}
public byte[] ContentData {
get {
return contentData;
}
}
public string BuildAction {
get {
return buildAction ?? "";

2
src/Main/Base/Project/Src/Internal/Templates/File/ScriptRunner.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -33,6 +33,8 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
public string CompileScript(FileTemplate item, FileDescriptionTemplate file)
{
if (file.Content == null)
throw new ArgumentException("file must have textual content");
Match m = scriptRegex.Match(file.Content);
m = m.NextMatch();
if (m.Success) {

14
src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs

@ -202,11 +202,15 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -202,11 +202,15 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
if (!Directory.Exists(Path.GetDirectoryName(fileName))) {
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
}
Properties properties = ((Properties)PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties()));
StreamWriter sr = new StreamWriter(File.Create(fileName), Encoding.GetEncoding(properties.Get("Encoding", 1252)));
sr.Write(StringParser.Parse(StringParser.Parse(file.Content, new string[,] { {"ProjectName", projectCreateInformation.ProjectName}, {"FileName", fileName}})));
sr.Close();
if (file.ContentData != null) {
// Binary content
File.WriteAllBytes(fileName, file.ContentData);
} else {
// Textual content
StreamWriter sr = new StreamWriter(File.Create(fileName), ParserService.DefaultFileEncoding);
sr.Write(StringParser.Parse(StringParser.Parse(file.Content, new string[,] { {"ProjectName", projectCreateInformation.ProjectName}, {"FileName", fileName}})));
sr.Close();
}
} catch (Exception ex) {
StringParser.Properties["fileName"] = fileName;
MessageService.ShowError(ex, "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.FileCouldntBeWrittenError}");

2
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs

@ -42,11 +42,13 @@ namespace SearchAndReplace @@ -42,11 +42,13 @@ namespace SearchAndReplace
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm"));
Get<Button>("findAll").Click += FindAllButtonClicked;
Get<Button>("bookmarkAll").Click += BookmarkAllButtonClicked;
this.ParentForm.AcceptButton = Get<Button>("findNext");
break;
case SearchAndReplaceMode.Replace:
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.ReplacePanel.xfrm"));
Get<Button>("replace").Click += ReplaceButtonClicked;
Get<Button>("replaceAll").Click += ReplaceAllButtonClicked;
this.ParentForm.AcceptButton = Get<Button>("replace");
break;
}

Loading…
Cancel
Save