Skip to content

Commit

Permalink
Add DDL script (.sql) file to project, not %temp%
Browse files Browse the repository at this point in the history
related to #2141
  • Loading branch information
ErikEJ committed Feb 5, 2024
1 parent 79cf260 commit bd6b83f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
30 changes: 20 additions & 10 deletions src/GUI/Shared/Extensions/ProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Community.VisualStudio.Toolkit;
using EFCorePowerTools.Handlers.ReverseEngineer;
Expand Down Expand Up @@ -266,7 +267,7 @@ public static async Task<bool> IsInstalledAsync(this Project project, NuGetPacka
return false;
}

public static List<string> GenerateFiles(this Project project, List<Tuple<string, string>> result, string extension)
public static List<string> GenerateFiles(this Project project, List<Tuple<string, string>> result, string extension, bool addToProject = false)
{
ThreadHelper.ThrowIfNotOnUIThread();

Expand All @@ -281,19 +282,28 @@ public static List<string> GenerateFiles(this Project project, List<Tuple<string
return list;
}

var filePath = Path.Combine(
Path.GetTempPath(),
item.Item1 + extension);

if (File.Exists(filePath))
if (addToProject)
{
File.SetAttributes(filePath, FileAttributes.Normal);
var itemPath = Path.Combine(Path.GetDirectoryName(project.FullPath), item.Item1 + extension);
File.WriteAllText(itemPath, item.Item2, Encoding.UTF8);
list.Add(itemPath);
}
else
{
var filePath = Path.Combine(
Path.GetTempPath(),
item.Item1 + extension);

if (File.Exists(filePath))
{
File.SetAttributes(filePath, FileAttributes.Normal);
}

File.WriteAllText(filePath, item.Item2);
File.SetAttributes(filePath, FileAttributes.ReadOnly);
File.WriteAllText(filePath, item.Item2, Encoding.UTF8);
File.SetAttributes(filePath, FileAttributes.ReadOnly);

list.Add(filePath);
list.Add(filePath);
}
}

return list;
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Shared/Handlers/ModelAnalyzerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async System.Threading.Tasks.Task GenerateAsync(string outputPath, Projec
Telemetry.TrackEvent("PowerTools.GenerateModelDgml");
break;
case GenerationType.Ddl:
var files = project.GenerateFiles(modelResult, ".sql");
var files = project.GenerateFiles(modelResult, ".sql", addToProject: true);
foreach (var file in files)
{
await VS.Documents.OpenAsync(file);
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Shared/Handlers/ProcessLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private async Task<string> GetOutputInternalAsync(string outputPath, string proj

try
{
File.WriteAllText(Path.Combine(Path.GetTempPath(), "efptparams.txt"), startInfo.Arguments);
File.WriteAllText(Path.Combine(Path.GetTempPath(), "efptparams.txt"), startInfo.Arguments, Encoding.UTF8);
}
catch
{
Expand Down
3 changes: 2 additions & 1 deletion src/GUI/Shared/Handlers/ReverseEngineer/EfRevEngLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using EFCorePowerTools.Extensions;
using RevEng.Common;
Expand Down Expand Up @@ -195,7 +196,7 @@ private async Task<ProcessStartInfo> CreateStartInfoAsync(string arguments)
private async Task<ReverseEngineerResult> GetOutputAsync()
{
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()) + ".json";
File.WriteAllText(path, options.Write());
File.WriteAllText(path, options.Write(), Encoding.UTF8);

var launchPath = DropNetCoreFiles();

Expand Down

0 comments on commit bd6b83f

Please sign in to comment.