Example #1
0
        public static void ReadProfilesFromFile()
        {
            XDocument XmlProfiles;

            if (File.Exists(ProfilesFile))
            {
                XmlProfiles = XDocument.Load(ProfilesFile, LoadOptions.PreserveWhitespace);
            }
            else
            {
                ProfilesFileMissingAtStartup = true;

                // try to detect Oculus HMD and set default profile accordingly
                if (FormMain.OculusConn.OculusHMDConnected())
                {
                    XmlProfiles = XDocument.Parse(CableGuardian.Properties.Resources.CGProfiles_Default_Oculus, LoadOptions.PreserveWhitespace);
                }
                else
                {
                    XmlProfiles = XDocument.Parse(CableGuardian.Properties.Resources.CGProfiles_Default_OpenVR, LoadOptions.PreserveWhitespace);
                }
            }

            if (XmlProfiles != null)
            {
                XElement xBase = XmlProfiles.Element(ProfilesName);
                if (xBase != null)
                {
                    LoadProfilesFromXml(xBase);
                }
            }
        }
        private void SaveProfiles()
        {
            var quickSelectProfiles =
                ProfileList.Where(profile => profile.Type == ProfileType.QuickSelect).Cast <QuickSelectProfile>().ToList();

            quickSelectProfiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var x264Profiles =
                ProfileList.Where(profile => profile.Type == ProfileType.X264).Cast <X264Profile>().ToList();

            x264Profiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var hcEncProfiles =
                ProfileList.Where(profile => profile.Type == ProfileType.HcEnc).Cast <HcEncProfile>().ToList();

            hcEncProfiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var vp8Profiles =
                ProfileList.Where(profile => profile.Type == ProfileType.Vp8).Cast <Vp8Profile>().ToList();

            vp8Profiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var ac3Profiles =
                ProfileList.Where(profile => profile.Type == ProfileType.Ac3).Cast <Ac3Profile>().ToList();

            ac3Profiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var mp3Profiles =
                ProfileList.Where(profile => profile.Type == ProfileType.Mp3).Cast <Mp3Profile>().ToList();

            mp3Profiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var oggProfiles =
                ProfileList.Where(profile => profile.Type == ProfileType.Ogg).Cast <OggProfile>().ToList();

            oggProfiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var aacProfiles =
                ProfileList.Where(profile => profile.Type == ProfileType.Aac).Cast <AacProfile>().ToList();

            aacProfiles.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal));

            var profiles = new XmlProfiles
            {
                Ac3Profiles =
                    ac3Profiles,
                HcEncProfiles =
                    hcEncProfiles,
                Mp3Profiles =
                    mp3Profiles,
                OggProfiles =
                    oggProfiles,
                QuickSelectProfiles =
                    quickSelectProfiles,
                X264Profiles =
                    x264Profiles,
                AacProfiles = aacProfiles,
                Vp8Profiles = vp8Profiles,
            };

            var serializer = new XmlSerializer(typeof(XmlProfiles));

            using (var writer = new FileStream(_profFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                serializer.Serialize(writer, profiles);
            }
            ReloadProfiles();
        }