Skip to content
Permalink
Browse files

[Assets] Removed AssetItem.SourceProject

  • Loading branch information
xen2 committed Aug 30, 2018
1 parent 1fd003c commit ab5281aed164b7438316fdce9f416d1ae093fa0e
@@ -358,7 +358,6 @@ private AssetDependencies TrackAsset(AssetId assetId)
: new AssetItem(assetItem.Location, AssetCloner.Clone(assetItem.Asset), assetItem.Package)
{
SourceFolder = assetItem.SourceFolder,
SourceProject = assetItem.SourceProject
};

dependencies = new AssetDependencies(assetItemCloned);
@@ -68,8 +68,6 @@ internal AssetItem([NotNull] UFile location, [NotNull] Asset asset, Package pack
/// <value>The directory.</value>
public UDirectory SourceFolder { get; set; }

public UFile SourceProject { get; set; }

/// <summary>
/// Gets the unique identifier of this asset.
/// </summary>
@@ -134,8 +132,7 @@ public AssetItem Clone(bool keepPackage, UFile newLocation = null, Asset newAsse
{
isDirty = isDirty,
SourceFolder = SourceFolder,
SourceProject = SourceProject,
version = Version
version = Version,
};
YamlMetadata.CopyInto(item.YamlMetadata);
return item;
@@ -263,7 +260,7 @@ public AssetItem FindBase()
}

/// <summary>
/// In case <see cref="SourceFolder"/> or <see cref="SourceProject"/> were null, generates them.
/// In case <see cref="SourceFolder"/> was null, generates it.
/// </summary>
public void UpdateSourceFolders()
{
@@ -17,7 +17,7 @@ public static class AssetItemExtensions
public static string GetProjectInclude([NotNull] this AssetItem assetItem)
{
var assetFullPath = assetItem.FullPath;
var projectFullPath = assetItem.SourceProject;
var projectFullPath = assetItem.Package.ProjectFullPath;
return assetFullPath.MakeRelative(projectFullPath.GetFullDirectory()).ToWindowsPath();
}

@@ -444,7 +444,6 @@ public Package Clone()
var assetItem = new AssetItem(asset.Location, newAsset)
{
SourceFolder = asset.SourceFolder,
SourceProject = asset.SourceProject
};
package.Assets.Add(assetItem);
}
@@ -608,7 +607,7 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
var projectAsset = asset.Asset as IProjectAsset;
if (projectAsset != null)
{
var projectFullPath = asset.SourceProject;
var projectFullPath = asset.Package.ProjectFullPath;
var projectInclude = asset.GetProjectInclude();

Project project;
@@ -1086,7 +1085,6 @@ private void LoadAsset(AssetMigrationContext context, PackageLoadingAssetFile as
{
IsDirty = assetContent != null || aliasOccurred,
SourceFolder = sourceFolder.MakeRelative(RootDirectory),
SourceProject = asset is IProjectAsset && assetFile.ProjectFile != null ? assetFile.ProjectFile : null,
};
yamlMetadata.CopyInto(assetItem.YamlMetadata);

@@ -1226,7 +1224,7 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters
}

/// <summary>
/// In case <see cref="AssetItem.SourceFolder"/> or <see cref="AssetItem.SourceProject"/> were null, generates them.
/// In case <see cref="AssetItem.SourceFolder"/> was null, generates it.
/// </summary>
internal void UpdateSourceFolders(IReadOnlyCollection<AssetItem> assets)
{
@@ -1253,12 +1251,8 @@ internal void UpdateSourceFolders(IReadOnlyCollection<AssetItem> assets)
{
if (asset.SourceFolder == null)
{
if (ProjectFullPath != null)
{
asset.SourceProject = ProjectFullPath;
asset.SourceFolder = asset.SourceProject.GetFullDirectory().GetParent().MakeRelative(RootDirectory);
asset.IsDirty = true;
}
asset.SourceFolder = string.Empty;
asset.IsDirty = true;
}
}
else
@@ -1441,7 +1435,7 @@ private static void FindAssetsInProject(ICollection<PackageLoadingAssetFile> lis

foreach (var codePath in codePaths)
{
list.Add(new PackageLoadingAssetFile(codePath, parentDir, realFullPath));
list.Add(new PackageLoadingAssetFile(codePath, parentDir));
}
}
}
@@ -17,7 +17,6 @@ public class PackageLoadingAssetFile
{
public readonly UFile FilePath;
public readonly UDirectory SourceFolder;
public readonly UFile ProjectFile;

public long CachedFileSize;

@@ -37,14 +36,6 @@ public PackageLoadingAssetFile(UFile filePath, UDirectory sourceFolder)
{
FilePath = filePath;
SourceFolder = sourceFolder;
ProjectFile = null;
}

public PackageLoadingAssetFile(UFile filePath, UDirectory sourceFolder, UFile projectFile)
{
FilePath = filePath;
SourceFolder = sourceFolder;
ProjectFile = projectFile;
}

/// <summary>
@@ -61,7 +52,6 @@ public PackageLoadingAssetFile(Package package, UFile filePath, UDirectory sourc

SourceFolder = UPath.Combine(package.RootDirectory, sourceFolder ?? package.GetDefaultAssetFolder());
FilePath = UPath.Combine(SourceFolder, filePath);
ProjectFile = null;
}

public IReference ToReference()
@@ -595,18 +595,19 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
try
{
//If we are within a csproj we need to remove the file from there as well
if (assetItem?.SourceProject != null)
var projectFullPath = assetItem.Package.ProjectFullPath;
if (projectFullPath != null)
{
var projectAsset = assetItem.Asset as IProjectAsset;
if (projectAsset != null)
{
var projectInclude = assetItem.GetProjectInclude();

Microsoft.Build.Evaluation.Project project;
if (!vsProjs.TryGetValue(assetItem.SourceProject, out project))
if (!vsProjs.TryGetValue(projectFullPath, out project))
{
project = VSProjectHelper.LoadProject(assetItem.SourceProject);
vsProjs.Add(assetItem.SourceProject, project);
project = VSProjectHelper.LoadProject(projectFullPath);
vsProjs.Add(projectFullPath, project);
}
var projectItem = project.Items.FirstOrDefault(x => (x.ItemType == "Compile" || x.ItemType == "None") && x.EvaluatedInclude == projectInclude);
if (projectItem != null && !projectItem.IsImported)
@@ -44,7 +44,6 @@ public AssetItemMutable(AssetItem item)
Location = item.Location;
SourceFolder = item.SourceFolder;
Asset = item.Asset;
ProjectFile = item.SourceProject;
}

[DataMember(0)]
@@ -57,12 +56,9 @@ public AssetItemMutable(AssetItem item)
[DataMember(2)]
public Asset Asset;

[DataMember(3)]
public UFile ProjectFile;

public AssetItem ToAssetItem()
{
return new AssetItem(Location, Asset) { SourceFolder = SourceFolder, SourceProject = ProjectFile };
return new AssetItem(Location, Asset) { SourceFolder = SourceFolder };
}
}

@@ -289,7 +289,6 @@ private static void AddNewProjectAssets(ProjectViewModel projectViewModel, List<
{
IsDirty = true, //todo review / this is actually very important in the case of renaming, to propagate the change from VS to Game Studio, if we set it false here, during renaming the renamed asset won't be removed
SourceFolder = projectViewModel.Package.RootDirectory,
SourceProject = projFile.ToWindowsPath(),
};

var directory = projectViewModel.Package.GetOrCreateProjectDirectory(projectViewModel, assetItem.Location.GetFullDirectory().FullPath, false);
@@ -254,7 +254,7 @@ private void TrackDocument()
// New asset, let's create it in the workspace
// TODO: Differentiate document (newly created should be added in the project by the asset creation code) and additional documents (not in project)?
AssetItem.UpdateSourceFolders();
var sourceProject = AssetItem.SourceProject?.ToWindowsPath();
var sourceProject = AssetItem.Package.ProjectFullPath?.ToWindowsPath();
if (sourceProject == null)
throw new InvalidOperationException($"Could not find project associated to asset [{AssetItem}]");

@@ -976,11 +976,11 @@ private async Task Paste()
var location = UPath.Combine(directory.Path, assetItem.Location);

// Check if we are pasting to package or a project (with a source code)
// TODO CSPROJ=XKPKG review
if (project != null)
{
// Link source project
assetItem.SourceFolder = project.Package.RootDirectory;
assetItem.SourceProject = project.ProjectPath.ToWindowsPath();
}

// Resolve folders to paste collisions with those existing in a directory
@@ -513,7 +513,7 @@ private bool UpdateUrl(Package newPackage, DirectoryBaseViewModel newDirectory,
package.Assets.Remove(AssetItem);
package = newPackage;

var newAssetItem = new AssetItem(newUrl, AssetItem.Asset) { SourceFolder = AssetItem.SourceFolder, SourceProject = AssetItem.SourceProject };
var newAssetItem = new AssetItem(newUrl, AssetItem.Asset) { SourceFolder = AssetItem.SourceFolder };
AssetItem = newAssetItem;
package.Assets.Add(AssetItem);
}
@@ -79,7 +79,7 @@ public ListBuildStep CreateSystemShaderBuildSteps(SessionViewModel session)
foreach (var asset in package.Assets)
{
if (typeof(EffectShaderAsset).IsAssignableFrom(asset.AssetType))
mapPackage.Assets.Add(new AssetItem(asset.Url, asset.Asset) { SourceFolder = asset.AssetItem.SourceFolder, SourceProject = asset.AssetItem.SourceProject });
mapPackage.Assets.Add(new AssetItem(asset.Url, asset.Asset) { SourceFolder = asset.AssetItem.SourceFolder });
}

importShadersProjectSession.Packages.Add(mapPackage);
@@ -114,7 +114,7 @@ public ListBuildStep CreateUserShaderBuildSteps(SessionViewModel session)
{
if (typeof(EffectShaderAsset).IsAssignableFrom(asset.AssetType))
{
mapPackage.Assets.Add(new AssetItem(asset.Url, asset.Asset) { SourceFolder = asset.AssetItem.SourceFolder, SourceProject = asset.AssetItem.SourceProject });
mapPackage.Assets.Add(new AssetItem(asset.Url, asset.Asset) { SourceFolder = asset.AssetItem.SourceFolder });
}
}

@@ -175,7 +175,7 @@ public VisualScriptCompilerResult Compile(AssetItem assetItem)
// Try to get root namespace from containing project
// Since ProjectReference.Location is sometimes absolute sometimes not, we have to handle both case
// TODO: ideally we should stop converting those and handle this automatically in a custom Yaml serializer?
var sourceProjectAbsolute = assetItem.SourceProject;
var sourceProjectAbsolute = assetItem.Package.ProjectFullPath;
var sourceProjectRelative = sourceProjectAbsolute?.MakeRelative(assetItem.Package.FullPath.GetFullDirectory());
var projectReference = assetItem.Package.Profiles.SelectMany(x => x.ProjectReferences).FirstOrDefault(x => x.Location == (x.Location.IsAbsolute ? sourceProjectAbsolute : sourceProjectRelative));

0 comments on commit ab5281a

Please sign in to comment.
You can’t perform that action at this time.