Пример #1
0
        public static bool ParseCellMaps(UFile file, List <UFile> textures, List <SpriteStudioCell> cells)
        {
            var xmlDoc = XDocument.Load(file);

            if (xmlDoc.Root == null)
            {
                return(false);
            }

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value");

            foreach (var cellMap in cellMaps)
            {
                var mapFile = UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value));
                var cellDoc = XDocument.Load(mapFile);
                if (cellDoc.Root == null)
                {
                    return(false);
                }

                var cnameSpace = cellDoc.Root.Name.Namespace;

                var cellNodes = cellDoc.Descendants(nameSpace + "cell");
                foreach (var cellNode in cellNodes)
                {
                    var cell = new SpriteStudioCell
                    {
                        Name         = cellNode.Descendants(cnameSpace + "name").First().Value,
                        TextureIndex = textures.Count
                    };

                    var posData    = cellNode.Descendants(nameSpace + "pos").First().Value;
                    var posValues  = Regex.Split(posData, "\\s+");
                    var sizeData   = cellNode.Descendants(nameSpace + "size").First().Value;
                    var sizeValues = Regex.Split(sizeData, "\\s+");
                    cell.Rectangle = new RectangleF(
                        float.Parse(posValues[0], CultureInfo.InvariantCulture),
                        float.Parse(posValues[1], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[0], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[1], CultureInfo.InvariantCulture));

                    var pivotData   = cellNode.Descendants(nameSpace + "pivot").First().Value;
                    var pivotValues = Regex.Split(pivotData, "\\s+");
                    cell.Pivot = new Vector2((float.Parse(pivotValues[0], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Width, (-float.Parse(pivotValues[1], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Height);

                    cells.Add(cell);
                }

                var textPath = cellDoc.Descendants(nameSpace + "imagePath").First().Value;

                textures.Add(UPath.Combine(file.GetFullDirectory(), new UFile(textPath)));
            }

            return(true);
        }
Пример #2
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);
                    }
                }
            }
Пример #3
0
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public static bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile();
                foreach (var entry in profile.Settings.Values)
                {
                    settingsFile.Settings.Add(entry.Name, entry.GetSerializableValue());
                }

                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    YamlSerializer.Serialize(stream, settingsFile);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while saving settings file [{0}]: {1}", e, filePath, Extensions.StringExtensions.FormatExceptionForReport(e));
                return(false);
            }
            finally
            {
                profile.Saving = false;
            }
            return(true);
        }
Пример #4
0
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile(profile);
                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    YamlSerializer.Serialize(stream, settingsFile);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while saving settings file [{0}]: {1}", e, filePath, e.FormatForReport());
                return(false);
            }
            finally
            {
                profile.Saving = false;
            }
            return(true);
        }
Пример #5
0
        public static bool SanityCheck(UFile file)
        {
            var xmlDoc = XDocument.Load(file);

            if (xmlDoc.Root == null)
            {
                return(false);
            }

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value").ToList();

            return(cellMaps.Select(cellMap => UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value))).All(fileName => File.Exists(fileName.ToWindowsPath())));
        }
Пример #6
0
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public bool SaveSettingsProfile([NotNull] SettingsProfile profile, [NotNull] UFile filePath)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile(profile);
                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    SettingsYamlSerializer.Default.Serialize(stream, settingsFile);
                }

                if (filePath != profile.FilePath)
                {
                    if (File.Exists(profile.FilePath))
                    {
                        File.Delete(profile.FilePath);
                    }

                    profile.FilePath = filePath;
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Error while saving settings file [{filePath}]", e);
                return(false);
            }
            finally
            {
                profile.Saving = false;
            }
            return(true);
        }
Пример #7
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);
        }