Ejemplo n.º 1
0
        private void LoadApplications()
        {
            Applications.Clear();

            try
            {
                var dir = new DirectoryInfo(applicationsPath.Value);
                if (dir.Exists)
                {
                    foreach (var file in dir.EnumerateFiles())
                    {
                        try
                        {
                            Applications.Add(UnrealApplicationSettings.ReadFromFile(file.FullName));
                        }
                        catch (Exception ex)
                        {
                            Program.ShowException(ex);
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {
                // ignore
            }
        }
Ejemplo n.º 2
0
        internal static void DeleteApplication(UnrealApplicationSettings settings)
        {
            Contract.Requires(settings != null);

            var path = Path.Combine(applicationsPath.Value, GetFilenameFromApplication(settings));

            File.Delete(path);
        }
        public static void WriteToFile(UnrealApplicationSettings settings, string path)
        {
            Contract.Requires(settings != null);
            Contract.Requires(path != null);

            var element = ToXml(settings);

            using (var sw = new StreamWriter(path))
            {
                element.Save(sw);
            }
        }
Ejemplo n.º 4
0
        private static string GetFilenameFromApplication(UnrealApplicationSettings settings)
        {
            Contract.Requires(settings != null);

            var name = settings.Name;

            foreach (var c in Path.GetInvalidFileNameChars())
            {
                name = name.Replace(c, '_');
            }
            return($"{name}.xml");
        }
Ejemplo n.º 5
0
        private void SaveApplications()
        {
            Directory.CreateDirectory(applicationsPath.Value);

            foreach (var app in Applications)
            {
                var path = Path.Combine(applicationsPath.Value, GetFilenameFromApplication(app));

                try
                {
                    UnrealApplicationSettings.WriteToFile(app, path);
                }
                catch (Exception ex)
                {
                    Program.ShowException(ex);
                }
            }
        }
        public static UnrealApplicationSettings FromXml(XElement element)
        {
            var settings = new UnrealApplicationSettings();

            XElementSerializer.TryRead(element, nameof(settings.Name), e => settings.Name               = XElementSerializer.ToString(e));
            XElementSerializer.TryRead(element, nameof(settings.Version), e => settings.Version         = (UnrealEngineVersion)XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.ProcessName), e => settings.ProcessName = XElementSerializer.ToString(e));

            XElementSerializer.TryRead(element, nameof(settings.PatternMethod), e => settings.PatternMethod = (PatternMethod)XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.PatternModule), e => settings.PatternModule = XElementSerializer.ToString(e));
            XElementSerializer.TryRead(element, nameof(settings.Pattern), e => settings.Pattern             = XElementSerializer.ToString(e));
            XElementSerializer.TryRead(element, nameof(settings.PatternOffset), e => settings.PatternOffset = XElementSerializer.ToInt(e));

            XElementSerializer.TryRead(element, nameof(settings.UObjectNameOffset), e => settings.UObjectNameOffset               = XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.UObjectOuterOffset), e => settings.UObjectOuterOffset             = XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.FNameEntryIndexOffset), e => settings.FNameEntryIndexOffset       = XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.FNameEntryNameDataOffset), e => settings.FNameEntryNameDataOffset = XElementSerializer.ToInt(e));
            XElementSerializer.TryRead(element, nameof(settings.FNameEntryIsWide), e => settings.FNameEntryIsWide = XElementSerializer.ToBool(e));

            XElementSerializer.TryRead(element, nameof(settings.DisplayFullName), e => settings.DisplayFullName = XElementSerializer.ToBool(e));

            return(settings);
        }
        public static XElement ToXml(UnrealApplicationSettings settings)
        {
            Contract.Requires(settings != null);

            return(new XElement(
                       RootElement,
                       new XElement(nameof(settings.Name), settings.Name),
                       new XElement(nameof(settings.Version), (int)settings.Version),
                       new XElement(nameof(settings.ProcessName), settings.ProcessName),

                       new XElement(nameof(settings.PatternMethod), (int)settings.PatternMethod),
                       new XElement(nameof(settings.PatternModule), settings.PatternModule),
                       new XElement(nameof(settings.Pattern), settings.Pattern),
                       new XElement(nameof(settings.PatternOffset), settings.PatternOffset),

                       new XElement(nameof(settings.UObjectNameOffset), settings.UObjectNameOffset),
                       new XElement(nameof(settings.UObjectOuterOffset), settings.UObjectOuterOffset),
                       new XElement(nameof(settings.FNameEntryIndexOffset), settings.FNameEntryIndexOffset),
                       new XElement(nameof(settings.FNameEntryNameDataOffset), settings.FNameEntryNameDataOffset),
                       new XElement(nameof(settings.FNameEntryIsWide), settings.FNameEntryIsWide),

                       new XElement(nameof(settings.DisplayFullName), settings.DisplayFullName)
                       ));
        }