示例#1
0
            void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
            {
                resourcesSourceToTarget.Add(resourceFilePath, 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()}]");
                }
                else
                {
                    resourcesTargetToSource.Add(targetFilePath, resourceFilePath);

                    try
                    {
                        Directory.CreateDirectory(targetFilePath.GetFullDirectory());
                        File.Copy(resourceFilePath, targetFilePath, true);

                        RegisterItem(targetFilePath);
                    }
                    catch (Exception e)
                    {
                        logger.Error($"Could not copy resource file from [{resourceFilePath.ToWindowsPath()}] to [{targetFilePath.MakeRelative(resourceOutputPath)}]", e);
                    }
                }
            }
示例#2
0
        /// <summary>
        /// Adds an exiting project to this package.
        /// </summary>
        /// <param name="pathToMsproj">The path to msproj.</param>
        /// <param name="logger">The logger.</param>
        public void AddExitingProject(UFile pathToMsproj, LoggerResult logger)
        {
            if (pathToMsproj == null)
            {
                throw new ArgumentNullException("pathToMsproj");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (!pathToMsproj.IsAbsolute)
            {
                throw new ArgumentException("Expecting relative path", "pathToMsproj");
            }

            try
            {
                // Load a project without specifying a platform to make sure we get the correct platform type
                var msProject = VSProjectHelper.LoadProject(pathToMsproj, platform: "NoPlatform");
                try
                {
                    var projectType = VSProjectHelper.GetProjectTypeFromProject(msProject);
                    if (!projectType.HasValue)
                    {
                        logger.Error("This project is not a project created with the editor");
                    }
                    else
                    {
                        var platformType = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;

                        var projectReference = new ProjectReference()
                        {
                            Id       = VSProjectHelper.GetProjectGuid(msProject),
                            Location = pathToMsproj.MakeRelative(RootDirectory),
                            Type     = projectType.Value
                        };

                        // Add the ProjectReference only for the compatible profiles (same platform or no platform)
                        foreach (var profile in Profiles.Where(profile => platformType == profile.Platform))
                        {
                            profile.ProjectReferences.Add(projectReference);
                        }
                    }
                }
                finally
                {
                    msProject.ProjectCollection.UnloadAllProjects();
                    msProject.ProjectCollection.Dispose();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Unexpected exception while loading project [{0}]", ex, pathToMsproj);
            }
        }
示例#3
0
        /// <summary>
        /// Handles project asset addition (from Visual Studio/HDD external changes to Game Studio).
        /// </summary>
        private static void AddNewProjectAssets(ProjectViewModel projectViewModel, List <AssetViewModel> projectAssets, Project project, List <UFile> projectFiles)
        {
            // Nothing to add?
            if (projectFiles.Count == 0)
            {
                return;
            }

            var scriptAssets = projectAssets.Where(x => x.AssetItem.Asset is IProjectAsset).Select(x => x.AssetItem);

            var documentsToIgnore = (from scriptAsset in scriptAssets
                                     from document in projectFiles
                                     let ufileDoc = new UFile(document)
                                                    where ufileDoc == scriptAsset.FullPath
                                                    select document).ToList();

            //remove what we have already
            var documentsCopy = new List <UFile>(projectFiles);

            foreach (var document in documentsToIgnore)
            {
                documentsCopy.Remove(document);
            }

            //add what we are missing
            if (documentsCopy.Count > 0)
            {
                var newScriptAssets = new List <AssetViewModel>();
                foreach (var document in documentsCopy)
                {
                    var docFile  = new UFile(document);
                    var projFile = new UFile(project.FilePath);

                    var assetName = docFile.MakeRelative(projectViewModel.Package.RootDirectory).GetDirectoryAndFileNameWithoutExtension();

                    var asset     = new ScriptSourceFileAsset();
                    var assetItem = new AssetItem(assetName, asset)
                    {
                        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);
                    var newScriptAsset = projectViewModel.Package.CreateAsset(directory, assetItem, false, null);
                    newScriptAssets.Add(newScriptAsset);
                }

                // We're out of any transaction in this context so we have to manually notify that new assets were created.
                projectViewModel.Session.NotifyAssetPropertiesChanged(newScriptAssets);
            }
        }
示例#4
0
        /// <inheritdoc/>
        public override string ToString()
        {
            var result = FilePath.MakeRelative(SourceFolder).ToString();

            if (AssetContent != null)
            {
                result += " (Modified)";
            }
            else if (Deleted)
            {
                result += " (Deleted)";
            }

            return(result);
        }
示例#5
0
        public void TestMakeRelativeWithDrive()
        {
            UPath assetPath2    = null;
            UPath newAssetPath2 = null;
            var   dir1          = new UDirectory("C:/a/b/c");

            // Test direct relative
            assetPath2    = new UFile("C:/a/b/c/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("test.txt", newAssetPath2.FullPath);

            // Test direct relative + subdir
            assetPath2    = new UFile("C:/a/b/c/test/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("test/test.txt", newAssetPath2.FullPath);

            // Test relative 1
            assetPath2    = new UFile("C:/a/b/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../test.txt", newAssetPath2.FullPath);

            // Test relative 2
            assetPath2    = new UFile("C:/a/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../test.txt", newAssetPath2.FullPath);

            // Test relative 3
            assetPath2    = new UFile("C:/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../../test.txt", newAssetPath2.FullPath);

            // Test already relative
            assetPath2    = new UFile("../test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../test.txt", newAssetPath2.FullPath);

            // Test no path in common
            assetPath2    = new UFile("E:/e/f/g/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("E:/e/f/g/test.txt", newAssetPath2.FullPath);

            // Test no root path single file
            assetPath2    = new UFile("E:/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("E:/test.txt", newAssetPath2.FullPath);
        }
示例#6
0
        public void TestMakeRelative()
        {
            UPath assetPath2    = null;
            UPath newAssetPath2 = null;
            var   dir1          = new UDirectory("/a/b/c");

            var assetDir2 = new UDirectory("/a/b/c");

            newAssetPath2 = dir1.MakeRelative(assetDir2);
            Assert.Equal(".", newAssetPath2.FullPath);

            var assetDir3 = new UDirectory("/a/b");

            newAssetPath2 = dir1.MakeRelative(assetDir3);
            Assert.Equal("c", newAssetPath2.FullPath);

            var assetDir4 = new UDirectory("/a/b/c/d");

            newAssetPath2 = dir1.MakeRelative(assetDir4);
            Assert.Equal("..", newAssetPath2.FullPath);

            // Test direct relative
            assetPath2    = new UFile("/a/b/c/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("test.txt", newAssetPath2.FullPath);

            // Test direct relative + subdir
            assetPath2    = new UFile("/a/b/c/test/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("test/test.txt", newAssetPath2.FullPath);

            // Test relative 1
            assetPath2    = new UFile("/a/b/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../test.txt", newAssetPath2.FullPath);

            // Test relative 2
            assetPath2    = new UFile("/a/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../test.txt", newAssetPath2.FullPath);

            // Test relative 3
            assetPath2    = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../../test.txt", newAssetPath2.FullPath);

            // Test already relative
            assetPath2    = new UFile("../test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../test.txt", newAssetPath2.FullPath);

            // Test only root path in common
            assetPath2    = new UFile("/e/f/g/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../../e/f/g/test.txt", newAssetPath2.FullPath);

            // Test only root path in common with single file
            assetPath2    = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.Equal("../../../test.txt", newAssetPath2.FullPath);
        }
示例#7
0
        public void TestMakeRelativeWithDrive()
        {
            UPath assetPath2 = null;
            UPath newAssetPath2 = null;
            var dir1 = new UDirectory("C:/a/b/c");

            // Test direct relative
            assetPath2 = new UFile("C:/a/b/c/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test.txt", newAssetPath2.FullPath);

            // Test direct relative + subdir
            assetPath2 = new UFile("C:/a/b/c/test/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test/test.txt", newAssetPath2.FullPath);

            // Test relative 1
            assetPath2 = new UFile("C:/a/b/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test relative 2
            assetPath2 = new UFile("C:/a/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../test.txt", newAssetPath2.FullPath);

            // Test relative 3
            assetPath2 = new UFile("C:/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);

            // Test already relative
            assetPath2 = new UFile("../test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test no path in common
            assetPath2 = new UFile("E:/e/f/g/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("E:/e/f/g/test.txt", newAssetPath2.FullPath);

            // Test no root path single file
            assetPath2 = new UFile("E:/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("E:/test.txt", newAssetPath2.FullPath);
        }
示例#8
0
        public void TestMakeRelative()
        {
            UPath assetPath2 = null;
            UPath newAssetPath2 = null;
            var dir1 = new UDirectory("/a/b/c");

            var assetDir2 = new UDirectory("/a/b/c");
            newAssetPath2 = dir1.MakeRelative(assetDir2);
            Assert.AreEqual(".", newAssetPath2.FullPath);

            var assetDir3 = new UDirectory("/a/b");
            newAssetPath2 = dir1.MakeRelative(assetDir3);
            Assert.AreEqual("c", newAssetPath2.FullPath);

            var assetDir4 = new UDirectory("/a/b/c/d");
            newAssetPath2 = dir1.MakeRelative(assetDir4);
            Assert.AreEqual("..", newAssetPath2.FullPath);

            // Test direct relative
            assetPath2 = new UFile("/a/b/c/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test.txt", newAssetPath2.FullPath);

            // Test direct relative + subdir
            assetPath2 = new UFile("/a/b/c/test/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test/test.txt", newAssetPath2.FullPath);

            // Test relative 1
            assetPath2 = new UFile("/a/b/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test relative 2
            assetPath2 = new UFile("/a/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../test.txt", newAssetPath2.FullPath);

            // Test relative 3
            assetPath2 = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);

            // Test already relative
            assetPath2 = new UFile("../test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test only root path in common
            assetPath2 = new UFile("/e/f/g/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../e/f/g/test.txt", newAssetPath2.FullPath);

            // Test only root path in common with single file
            assetPath2 = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);
        }
示例#9
0
 void RegisterItem(UFile targetFilePath)
 {
     generatedItems.Add((targetFilePath.ToWindowsPath(), UPath.Combine("xenko", targetFilePath.MakeRelative(outputPath)).ToWindowsPath()));
 }