Ejemplo n.º 1
0
        private static Process FindVisualStudioInstance(UFile solutionPath)
        {
            // NOTE: this code is very hackish and does not 100% ensure that the correct instance of VS will be activated.
            var processes = Process.GetProcessesByName("devenv");

            foreach (var process in processes)
            {
                // Get instances that have a solution with the same name currently open (The solution name is displayed in the title bar).
                if (process.MainWindowTitle.ToLowerInvariant().StartsWith(solutionPath.GetFileNameWithoutExtension().ToLowerInvariant()))
                {
                    // If there is a matching instance, get its command line.
                    var query = $"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {process.Id}";
                    using (var managementObjectSearcher = new ManagementObjectSearcher(query))
                    {
                        var managementObject = managementObjectSearcher.Get().Cast <ManagementObject>().First();
                        var commandLine      = managementObject["CommandLine"].ToString();
                        if (commandLine.ToLowerInvariant().Replace("/", "\\").Contains(solutionPath.ToString().ToLowerInvariant().Replace("/", "\\")))
                        {
                            return(process);
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static AssetItem ImportSkeleton(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo)
        {
            var asset = new SkeletonAsset {
                Source = assetSource
            };

            if (entityInfo.Nodes != null)
            {
                foreach (var node in entityInfo.Nodes)
                {
                    var nodeInfo = new NodeInformation(node.Name, node.Depth, node.Preserve);
                    asset.Nodes.Add(nodeInfo);
                }
            }

            if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0)
            {
                asset.PreserveNodes(entityInfo.AnimationNodes);
            }

            var skeletonUrl = new UFile(localPath.GetFileNameWithoutExtension() + " Skeleton");
            var assetItem   = new AssetItem(skeletonUrl, asset);

            assetReferences.Add(assetItem);
            return(assetItem);
        }
Ejemplo n.º 3
0
        public void TestWithSimplePathWithExtension()
        {
            var assetPath = new UFile("/a/b/c.txt");

            Assert.Equal("/a/b", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("/a/b/c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("/a/b/c.txt", assetPath.FullPath);
        }
Ejemplo n.º 4
0
        public override IEnumerable <AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters)
        {
            var asset = new TextureAsset {
                Source = rawAssetPath
            };

            // Creates the url to the texture
            var textureUrl = new UFile(rawAssetPath.GetFileNameWithoutExtension());

            yield return(new AssetItem(textureUrl, asset));
        }
        private static AssetItem ImportVideo([NotNull] UFile sourcePath, [NotNull] VideoStream videoStream)
        {
            var videoAsset = new VideoAsset
            {
                Source = sourcePath,
            };

            videoAsset.VideoDuration.StartTime = TimeSpan.Zero;
            videoAsset.VideoDuration.EndTime   = videoStream.Duration;

            var videoUrl = new UFile(sourcePath.GetFileNameWithoutExtension());

            return(new AssetItem(videoUrl, videoAsset));
        }
Ejemplo n.º 6
0
        public sealed override IEnumerable <AssetItem> Import([NotNull] UFile rawAssetPath, AssetImporterParameters importParameters)
        {
            if (rawAssetPath == null)
            {
                throw new ArgumentNullException(nameof(rawAssetPath));
            }

            var asset = new TAsset {
                Source = rawAssetPath
            };
            // Creates the url to the raw asset
            var rawAssetUrl = new UFile(rawAssetPath.GetFileNameWithoutExtension());

            yield return(new AssetItem(rawAssetUrl, asset));
        }
Ejemplo n.º 7
0
 internal RecentProjectViewModel(LauncherViewModel launcher, UFile path)
     : base(launcher.SafeArgument(nameof(launcher)).ServiceProvider)
 {
     Name             = path.GetFileNameWithoutExtension();
     Launcher         = launcher;
     fullPath         = path;
     XenkoVersionName = Strings.ReportDiscovering;
     OpenCommand      = new AnonymousTaskCommand(ServiceProvider, () => OpenWith(null))
     {
         IsEnabled = false
     };
     OpenWithCommand    = new AnonymousTaskCommand <XenkoVersionViewModel>(ServiceProvider, OpenWith);
     ExploreCommand     = new AnonymousCommand(ServiceProvider, Explore);
     CompatibleVersions = new ObservableList <XenkoVersionViewModel>();
     DiscoverXenkoVersion();
 }
Ejemplo n.º 8
0
        private static void ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName, AssetItem skeletonAsset)
        {
            var asset = new ModelAsset {
                Source = assetSource
            };

            if (entityInfo.Models != null)
            {
                var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList();
                foreach (var material in entityInfo.Materials)
                {
                    var modelMaterial = new ModelMaterial
                    {
                        Name             = material.Key,
                        MaterialInstance = new MaterialInstance()
                    };
                    var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key));
                    if (foundMaterial != null)
                    {
                        var reference = AttachedReferenceManager.CreateProxyObject <Material>(foundMaterial.Id, foundMaterial.Location);
                        modelMaterial.MaterialInstance.Material = reference;
                    }
                    asset.Materials.Add(modelMaterial);
                }

                // Handle the case where during import we imported no materials at all
                if (entityInfo.Materials.Count == 0)
                {
                    var modelMaterial = new ModelMaterial {
                        Name = "Material", MaterialInstance = new MaterialInstance()
                    };
                    asset.Materials.Add(modelMaterial);
                }
            }

            if (skeletonAsset != null)
            {
                asset.Skeleton = AttachedReferenceManager.CreateProxyObject <Skeleton>(skeletonAsset.Id, skeletonAsset.Location);
            }

            var modelUrl  = new UFile(localPath.GetFileNameWithoutExtension() + (shouldPostFixName?" Model": ""));
            var assetItem = new AssetItem(modelUrl, asset);

            assetReferences.Add(assetItem);
        }
Ejemplo n.º 9
0
        private static void ImportAnimation(List <AssetItem> assetReferences, UFile localPath, List <string> animationNodes, bool shouldPostFixName, AssetItem skeletonAsset, TimeSpan animationStartTime, TimeSpan animationEndTime)
        {
            if (animationNodes != null && animationNodes.Count > 0)
            {
                var assetSource = localPath;

                var asset = new AnimationAsset {
                    Source = assetSource, AnimationTimeMaximum = animationEndTime, AnimationTimeMinimum = animationStartTime
                };
                var animUrl = localPath.GetFileNameWithoutExtension() + (shouldPostFixName ? " Animation" : "");

                if (skeletonAsset != null)
                {
                    asset.Skeleton = AttachedReferenceManager.CreateProxyObject <Skeleton>(skeletonAsset.Id, skeletonAsset.Location);
                }

                assetReferences.Add(new AssetItem(animUrl, asset));
            }
        }
Ejemplo n.º 10
0
        public void TestWithNormalization()
        {
            var assetPath = new UFile("/a/b/.././././//c.txt");

            Assert.Equal("/a", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("/a/c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("/a/c.txt", assetPath.FullPath);

            assetPath = new UFile("../.././././//c.txt");
            Assert.Equal("../..", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("../../c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("../../c.txt", assetPath.FullPath);

            assetPath = new UFile("a/../../../c.txt");
            Assert.Equal("../../c.txt", assetPath.FullPath);
        }
Ejemplo n.º 11
0
        private static void ImportTextures(IEnumerable <string> textureDependencies, List <AssetItem> assetReferences)
        {
            if (textureDependencies == null)
            {
                return;
            }

            foreach (var textureFullPath in textureDependencies.Distinct(x => x))
            {
                var texturePath = new UFile(textureFullPath);

                var source  = texturePath;
                var texture = new TextureAsset {
                    Source = source, PremultiplyAlpha = false
                };

                // Create asset reference
                assetReferences.Add(new AssetItem(texturePath.GetFileNameWithoutExtension(), texture));
            }
        }
Ejemplo n.º 12
0
        private void Rename(UFile packagePath)
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var previousPath = PackagePath;
                PackagePath = packagePath;

                if (previousPath != PackagePath)
                {
                    IsEditing = false;
                }
                UndoRedoService.SetName(transaction, $"Rename package '{previousPath.GetFileNameWithoutExtension()}' to '{packagePath.GetFileNameWithoutExtension()}'");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Launch <paramref name="exePath"/> on remote host using credentials stored in EditorSettings.
        /// Before launching all the files requires by <paramref name="exePath"/> are copied over to host
        /// using the location specified in EditorSettings.Location. If <paramref name="isCoreCLR"/> is set
        /// all the Stride native libraries are copied over to the current directory of the game on the remote
        /// host via the `CoreCLRSetup` script.
        /// </summary>
        /// <param name="logger">Logger to show progress and any issues that may occur.</param>
        /// <param name="exePath">Path on the local machine where the executable was compiled.</param>
        /// <param name="isCoreCLR">Is <paramref name="exePath"/> executed against .NET Core?</param>
        /// <returns>True when launch was successful, false otherwise.</returns>
        internal static bool Launch([NotNull] LoggerResult logger, [NotNull] UFile exePath, bool isCoreCLR)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (exePath == null)
            {
                throw new ArgumentNullException(nameof(exePath));
            }

            var host     = StrideEditorSettings.Host.GetValue();
            var username = StrideEditorSettings.Username.GetValue();
            var port     = StrideEditorSettings.Port.GetValue();
            var password = Decrypt(StrideEditorSettings.Password.GetValue());
            var location = new UDirectory(StrideEditorSettings.Location.GetValue());
            var display  = StrideEditorSettings.Display.GetValue();

            var connectInfo = NewConnectionInfo(host, port, username, password);

            if (SyncTo(connectInfo, exePath.GetFullDirectory(), UPath.Combine(location, new UDirectory(exePath.GetFileNameWithoutExtension())), logger))
            {
                var sshClient = new SshClient(connectInfo);
                try
                {
                    sshClient.Connect();
                    if (sshClient.IsConnected)
                    {
                        string     cmdString;
                        SshCommand cmd;

                        // Due to lack of Dllmap config for CoreCLR, we have to ensure that our native libraries
                        // are copied next to the executable. The CoreCLRSetup script will check the 32-bit vs 64-bit
                        // of the `dotnet` runner and copy the .so files from the proper x86 or x64 directory.
                        if (isCoreCLR)
                        {
                            cmdString = "bash -c 'source /etc/profile ; cd " + location + "/" + exePath.GetFileNameWithoutExtension() + ";" + "sh ./CoreCLRSetup.sh'";
                            cmd       = sshClient.CreateCommand(cmdString);
                            cmd.Execute();
                            var err = cmd.Error;
                            if (!string.IsNullOrEmpty(err))
                            {
                                logger.Error(err);
                                // We don't exit here in case of failure, we just print the error and continue
                                // Users can then try to fix the issue directly on the remote host.
                            }
                            else
                            {
                                err = cmd.Result;
                                if (!string.IsNullOrEmpty(err))
                                {
                                    logger.Info(err);
                                }
                            }
                        }
                        // Try to get the main IP of the machine
                        var ipv4             = GetAllLocalIPv4().FirstOrDefault();
                        var connectionRouter = string.Empty;
                        if (!string.IsNullOrEmpty(ipv4))
                        {
                            connectionRouter = " StrideConnectionRouterRemoteIP=" + ipv4;
                        }
                        var dotnetEngine = StrideEditorSettings.UseCoreCLR.GetValue() ? " dotnet " : " mono ";
                        if (!string.IsNullOrEmpty(display))
                        {
                            display = " DISPLAY=" + display;
                        }
                        else
                        {
                            display = " DISPLAY=:0.0";
                        }
                        cmdString = "bash -c 'source /etc/profile ; cd " + location + "/" + exePath.GetFileNameWithoutExtension() + ";" + display + connectionRouter + dotnetEngine + "./" + exePath.GetFileName() + "'";
                        cmd       = sshClient.CreateCommand(cmdString);
                        cmd.BeginExecute((callback) =>
                        {
                            var res = cmd.Error;
                            if (!string.IsNullOrEmpty(res))
                            {
                                logger.Error(res);
                            }
                            else
                            {
                                res = cmd.Result;
                                if (!string.IsNullOrEmpty(res))
                                {
                                    logger.Info(res);
                                }
                            }

                            // Dispose of our resources as soon as we are done.
                            cmd.Dispose();
                            sshClient.Dispose();
                        });
                        return(true);
                    }
                }
                catch (Exception)
                {
                    var message = Tr._p("Message", "Unable to launch {0} on host {1}");
                    logger.Error(string.Format(message, exePath, host));
                }
            }

            return(false);
        }