Skip to content

Commit

Permalink
fix: Replace ToWindowsPath with ToOSPath (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jklawreszuk authored Jul 6, 2024
1 parent c5bc5a2 commit d49ca78
Show file tree
Hide file tree
Showing 42 changed files with 77 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ private void SaveBuildUpToDateFile(string msbuildUpToDateCheckFileBase, string p
{
// Note: check if file exists (since it could be an "implicit package" from csproj)
if (File.Exists(package.FullPath))
inputs.Add(package.FullPath.ToWindowsPath());
inputs.Add(package.FullPath.ToOSPath());

// TODO: optimization: for nuget packages, directly use sha512 file rather than individual assets for faster checking

// List assets
foreach (var assetFolder in package.AssetFolders)
{
if (Directory.Exists(assetFolder.Path))
inputs.Add(assetFolder.Path.ToWindowsPath() + @"\**\*.*");
inputs.Add(assetFolder.Path.ToOSPath() + "/**/*.*".Replace('/', Path.DirectorySeparatorChar));
}

// List project assets
Expand All @@ -215,7 +215,7 @@ private void SaveBuildUpToDateFile(string msbuildUpToDateCheckFileBase, string p
{
// Make sure it is not already covered by one of the previously registered asset folders
if (!package.AssetFolders.Any(assetFolder => assetFolder.Path.Contains(assetItem.FullPath)))
inputs.Add(assetItem.FullPath.ToWindowsPath());
inputs.Add(assetItem.FullPath.ToOSPath());
}
}

Expand All @@ -233,7 +233,7 @@ private void SaveBuildUpToDateFile(string msbuildUpToDateCheckFileBase, string p
{
if (inputObject.Key.Type == UrlType.File)
{
inputs.Add(new UFile(inputObject.Key.Path).ToWindowsPath());
inputs.Add(new UFile(inputObject.Key.Path).ToOSPath());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool Run(Core.Diagnostics.Logger logger, string projectFile, strin

void RegisterItem(UFile targetFilePath)
{
generatedItems.Add((targetFilePath.ToWindowsPath(), UPath.Combine("stride", targetFilePath.MakeRelative(outputPath)).ToWindowsPath()));
generatedItems.Add((targetFilePath.ToOSPath(), UPath.Combine("stride", targetFilePath.MakeRelative(outputPath)).ToOSPath()));
}

void TryCopyDirectory(UDirectory sourceDirectory, UDirectory targetDirectory, string exclude = null)
Expand Down Expand Up @@ -70,7 +70,7 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)

if (resourcesTargetToSource.TryGetValue(targetFilePath, out var otherResourceFilePath))
{
logger.Error($"Could not copy resource file [{targetFilePath.MakeRelative(resourceOutputPath)}] because it exists in multiple locations: [{resourceFilePath.ToWindowsPath()}] and [{otherResourceFilePath.ToWindowsPath()}]");
logger.Error($"Could not copy resource file [{targetFilePath.MakeRelative(resourceOutputPath)}] because it exists in multiple locations: [{resourceFilePath.ToOSPath()}] and [{otherResourceFilePath.ToOSPath()}]");
}
else
{
Expand All @@ -85,7 +85,7 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
}
catch (Exception e)
{
logger.Error($"Could not copy resource file from [{resourceFilePath.ToWindowsPath()}] to [{targetFilePath.MakeRelative(resourceOutputPath)}]", e);
logger.Error($"Could not copy resource file from [{resourceFilePath.ToOSPath()}] to [{targetFilePath.MakeRelative(resourceOutputPath)}]", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void TestUpgrade(MyUpgradedAsset asset, bool needMigration)
AssetFileSerializer.Save(outputFilePath, asset, null);

var logger = new LoggerResult();
var context = new AssetMigrationContext(null, loadingFilePath.ToReference(), loadingFilePath.FilePath.ToWindowsPath(), logger);
var context = new AssetMigrationContext(null, loadingFilePath.ToReference(), loadingFilePath.FilePath.ToOSPath(), logger);
Assert.Equal(AssetMigration.MigrateAssetIfNeeded(context, loadingFilePath, "TestPackage"), needMigration);

if (needMigration)
Expand Down
2 changes: 1 addition & 1 deletion sources/assets/Stride.Core.Assets/AssetItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static string GetProjectInclude([NotNull] this AssetItem assetItem)
{
var assetFullPath = assetItem.FullPath;
var projectFullPath = (assetItem.Package.Container as SolutionProject)?.FullPath;
return assetFullPath.MakeRelative(projectFullPath.GetFullDirectory()).ToWindowsPath();
return assetFullPath.MakeRelative(projectFullPath.GetFullDirectory()).ToOSPath();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ListBuildStep CompileItem(AssetCompilerContext context, AssetCompilerResu
AssetCompiled?.Invoke(this, new AssetCompiledArgs(assetItem, resultPerAssetType));

// TODO: See if this can be unified with PackageBuilder.BuildStepProcessed
var assetFullPath = assetItem.FullPath.ToWindowsPath();
var assetFullPath = assetItem.FullPath.ToOSPath();
foreach (var message in resultPerAssetType.Messages)
{
var assetMessage = AssetLogMessage.From(null, assetItem.ToReference(), message, assetFullPath);
Expand All @@ -106,7 +106,7 @@ public ListBuildStep CompileItem(AssetCompilerContext context, AssetCompilerResu

// TODO: Big review of the log infrastructure of CompilerApp & BuildEngine!
// Assign module string to all command build steps
SetAssetLogger(resultPerAssetType.BuildSteps, assetItem.Package, assetItem.ToReference(), assetItem.FullPath.ToWindowsPath());
SetAssetLogger(resultPerAssetType.BuildSteps, assetItem.Package, assetItem.ToReference(), assetItem.FullPath.ToOSPath());

foreach (var buildStep in resultPerAssetType.BuildSteps)
{
Expand Down
8 changes: 4 additions & 4 deletions sources/assets/Stride.Core.Assets/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public static PackageContainer LoadProject(ILogger log, string filePath)

// Find the .csproj next to .sdpkg (if any)
// Note that we use package.FullPath since we must first perform package upgrade from 3.0 to 3.1+ (might move package in .csproj folder)
var projectPath = Path.ChangeExtension(package.FullPath.ToWindowsPath(), ".csproj");
var projectPath = Path.ChangeExtension(package.FullPath.ToOSPath(), ".csproj");
if (File.Exists(projectPath))
{
return new SolutionProject(package, Guid.NewGuid(), projectPath);
Expand Down Expand Up @@ -881,8 +881,8 @@ public void LoadTemporaryAssets(ILogger log, List<PackageLoadingAssetFile> asset
loggerResult?.Progress(progressMessage, i, assetFiles.Count);

var task = cancelToken.HasValue ?
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(new AssetMigrationContext(this, assetFile.ToReference(), assetFile.FilePath.ToWindowsPath(), log), assetFile), cancelToken.Value) :
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(new AssetMigrationContext(this, assetFile.ToReference(), assetFile.FilePath.ToWindowsPath(), log), assetFile));
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(new AssetMigrationContext(this, assetFile.ToReference(), assetFile.FilePath.ToOSPath(), log), assetFile), cancelToken.Value) :
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(new AssetMigrationContext(this, assetFile.ToReference(), assetFile.FilePath.ToOSPath(), log), assetFile));

tasks.Add(task);
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ private void LoadAssemblyReferenceInternal(ILogger log, PackageLoadParameters lo
// If csproj, we might need to compile it
if (projectReference != null)
{
var fullProjectLocation = projectReference.Location.ToWindowsPath();
var fullProjectLocation = projectReference.Location.ToOSPath();
if (loadParameters.AutoCompileProjects || string.IsNullOrWhiteSpace(assemblyPath))
{
assemblyPath = VSProjectHelper.GetOrCompileProjectAssembly(Session?.SolutionPath, fullProjectLocation, forwardingLogger, "Build", loadParameters.AutoCompileProjects, loadParameters.BuildConfiguration, extraProperties: loadParameters.ExtraCompileProperties, onlyErrors: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
}
catch (Exception ex)
{
log.Error($"Unexpected exception while loading project [{project.FullPath.ToWindowsPath()}]", ex);
log.Error($"Unexpected exception while loading project [{project.FullPath.ToOSPath()}]", ex);
}

foreach (var packageReference in packageReferences)
Expand Down Expand Up @@ -182,7 +182,7 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
try
{
var projectFile = project.FullPath;
var msbuildProject = VSProjectHelper.LoadProject(projectFile.ToWindowsPath());
var msbuildProject = VSProjectHelper.LoadProject(projectFile.ToOSPath());
var isProjectDirty = false;

foreach (var packageReference in msbuildProject.GetItems("PackageReference").ToList())
Expand Down Expand Up @@ -238,7 +238,7 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
}
catch (Exception ex)
{
log.Error($"Unexpected exception while loading project [{project.FullPath.ToWindowsPath()}]", ex);
log.Error($"Unexpected exception while loading project [{project.FullPath.ToOSPath()}]", ex);
}
}

Expand Down
10 changes: 5 additions & 5 deletions sources/assets/Stride.Core.Assets/PackageSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void DirectDependencies_CollectionChanged(object sender, NotifyCollectio
return;

var projectFile = FullPath;
var msbuildProject = VSProjectHelper.LoadProject(projectFile.ToWindowsPath());
var msbuildProject = VSProjectHelper.LoadProject(projectFile.ToOSPath());
var isProjectDirty = false;

if (e.OldItems != null && e.OldItems.Count > 0)
Expand Down Expand Up @@ -380,7 +380,7 @@ private void DirectDependencies_CollectionChanged(object sender, NotifyCollectio
isProjectDirty = true;
break;
case DependencyType.Project:
msbuildProject.AddItem("ProjectReference", ((UFile)dependency.MSBuildProject).MakeRelative(projectFile.GetFullDirectory()).ToWindowsPath());
msbuildProject.AddItem("ProjectReference", ((UFile)dependency.MSBuildProject).MakeRelative(projectFile.GetFullDirectory()).ToOSPath());
isProjectDirty = true;
break;
}
Expand Down Expand Up @@ -646,7 +646,7 @@ public PackageContainer AddExistingProject(UFile projectPath, ILogger logger, Pa
// Enable reference analysis caching during loading
AssetReferenceAnalysis.EnableCaching = true;

project = LoadProject(logger, projectPath.ToWindowsPath(), loadParametersArg);
project = LoadProject(logger, projectPath.ToOSPath(), loadParametersArg);
Projects.Add(project);

package = project.Package;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
Microsoft.Build.Evaluation.Project project;
if (!vsProjs.TryGetValue(projectFullPath, out project))
{
project = VSProjectHelper.LoadProject(projectFullPath.ToWindowsPath());
project = VSProjectHelper.LoadProject(projectFullPath.ToOSPath());
vsProjs.Add(projectFullPath, project);
}
var projectItem = project.Items.FirstOrDefault(x => (x.ItemType == "Compile" || x.ItemType == "None") && x.EvaluatedInclude == projectInclude);
Expand All @@ -1058,7 +1058,7 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
var generatorAsset = assetItem.Asset as IProjectFileGeneratorAsset;
if (generatorAsset != null)
{
var generatedAbsolutePath = assetItem.GetGeneratedAbsolutePath().ToWindowsPath();
var generatedAbsolutePath = assetItem.GetGeneratedAbsolutePath().ToOSPath();

File.Delete(generatedAbsolutePath);

Expand Down
2 changes: 1 addition & 1 deletion sources/core/Stride.Core.Design.Tests/TestUPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void TestUPathToString()
}

[Fact]
public void TestUPathToWindowsPath()
public void TestUPathToOSPath()
{
// TODO
}
Expand Down
13 changes: 1 addition & 12 deletions sources/core/Stride.Core.Design/IO/UPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,7 @@ public override string ToString()
{
return FullPath;
}

/// <summary>
/// Converts this path to a Windows path (/ replaced by \)
/// </summary>
/// <returns>A string representation of this path in windows form.</returns>
[NotNull]
[Obsolete("Use ToOSPath() instead")]
public string ToWindowsPath()
{
return FullPath.Replace('/', '\\');
}


/// <summary>
/// Converts this path to a OS path,
/// by replacing each separator with the current operating system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private async Task RebuildLightProbes(int bounces)
private async Task CaptureCubemap()
{
var filepath = await ServiceProvider.Get<IDialogService>().SaveFilePickerAsync(
editor.Session.SolutionPath?.GetFullDirectory().ToWindowsPath(),
editor.Session.SolutionPath?.GetFullDirectory().ToOSPath(),
[new FilePickerFilter("DDS texture") { Patterns = ["*.dds"] }],
"dds");
if (filepath is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async Task TriggerBackgroundCompilation()

try
{
var generatedAbsolutePath = assetItem.GetGeneratedAbsolutePath()?.ToWindowsPath();
var generatedAbsolutePath = assetItem.GetGeneratedAbsolutePath()?.ToOSPath();
if (generatedAbsolutePath == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void LoadDefaultTemplates()
var packageFile = PackageStore.Instance.GetPackageFileName(packageInfo.Name, new PackageVersionRange(new PackageVersion(packageInfo.Version)));
if (packageFile is null)
throw new InvalidOperationException($"Could not find package {packageInfo.Name} {packageInfo.Version}. Ensure packages have been resolved.");
var package = Package.Load(logger, packageFile.ToWindowsPath());
var package = Package.Load(logger, packageFile.ToOSPath());
if (logger.HasErrors)
throw new InvalidOperationException($"Could not load package {packageInfo.Name}:{Environment.NewLine}{logger.ToText()}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ private void CreateAndSetNewScene(SessionTemplateGeneratorParameters parameters,
try
{
var resources = UPath.Combine(package.RootDirectory, (UDirectory)"Resources");
Directory.CreateDirectory(resources.ToWindowsPath());
Directory.CreateDirectory(resources.ToOSPath());

// TODO: Hardcoded due to the fact that part of the template is in another folder in dev build
// We might want to extend TemplateFolder to support those cases
var dataDirectory = ProjectTemplateGeneratorHelper.GetTemplateDataDirectory(parameters.Description);
var skyboxFullPath = UPath.Combine(dataDirectory, skyboxFilename).ToWindowsPath();
File.Copy(skyboxFullPath, UPath.Combine(resources, skyboxFilename).ToWindowsPath(), true);
var skyboxFullPath = UPath.Combine(dataDirectory, skyboxFilename).ToOSPath();
File.Copy(skyboxFullPath, UPath.Combine(resources, skyboxFilename).ToOSPath(), true);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override IEnumerable<AssetItem> CreateAssets(AssetTemplateGeneratorPar
{
using (var media = new FFmpegMedia())
{
media.Open(soundAsset.Source.ToWindowsPath());
media.Open(soundAsset.Source.ToOSPath());
var audioStreams = media.Streams.OfType<AudioStream>().ToList();
foreach (var audioTrack in audioStreams)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected override async Task<bool> AfterSave(SessionTemplateGeneratorParameters
if (!await updateTemplate.PrepareForRun(updateParameters) || !updateTemplate.Run(updateParameters))
{
// Remove the created project
var path = Path.GetDirectoryName(parameters.Session.SolutionPath.ToWindowsPath());
var path = Path.GetDirectoryName(parameters.Session.SolutionPath.ToOSPath());
try
{
Directory.Delete(path ?? "", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)
var templateGameLibrary = PrepareTemplate(parameters, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", PlatformType.Shared, null, null, ProjectType.Library);
var options = ProjectTemplateGeneratorHelper.GetOptions(parameters);
var newGameTargetFrameworks = templateGameLibrary.GeneratePart(@"..\Common.TargetFrameworks.targets.t4", logger, options);
PatchGameProject(newGameTargetFrameworks, gameProject.FullPath.ToWindowsPath());
PatchGameProject(newGameTargetFrameworks, gameProject.FullPath.ToOSPath());

// Generate missing platforms
bool forceGenerating = parameters.GetTag(ForcePlatformRegenerationKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override IEnumerable<AssetItem> CreateAssets(AssetTemplateGeneratorPar
{
using (var media = new FFmpegMedia())
{
media.Open(file.ToWindowsPath());
media.Open(file.ToOSPath());

var videoStream = media.Streams.OfType<VideoStream>().FirstOrDefault();
if (videoStream != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private static async Task<bool> DeleteRemovedProjectAssets(ProjectViewModel proj
var dialogResult = projectViewModel.Session.Dialogs.BlockingMessageBox(
string.Format(
Tr._p("Message", "The following source files in the {0} project have been deleted externally, but have unsaved changes in Game Studio. Do you want to delete these files?\r\n\r\n{1}"),
Path.GetFileName(project.FilePath), string.Join("\r\n", dirtyAssetsToDelete.Select(x => x.AssetItem.FullPath.ToWindowsPath()))),
Path.GetFileName(project.FilePath), string.Join("\r\n", dirtyAssetsToDelete.Select(x => x.AssetItem.FullPath.ToOSPath()))),
MessageBoxButton.OKCancel);
if (dialogResult == MessageBoxResult.Cancel)
return false;
Expand Down
Loading

0 comments on commit d49ca78

Please sign in to comment.