Exemplo n.º 1
0
        // End of NEW

        /// <summary>
        /// Configure profile from file to Asf file writer
        /// </summary>
        /// <param name="asfWriter"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool ConfigProfileFromFile(IBaseFilter asfWriter, string filename)
        {
            int hr;

            //string profilePath = "test.prx";
            // Set the profile to be used for conversion
            if ((filename != null) && (File.Exists(filename)))
            {
                // Load the profile XML contents
                string profileData;
                using (StreamReader reader = new StreamReader(File.OpenRead(filename)))
                {
                    profileData = reader.ReadToEnd();
                }

                // Create an appropriate IWMProfile from the data
                // Open the profile manager
                IWMProfileManager profileManager;
                IWMProfile        wmProfile = null;
                hr = WMLib.WMCreateProfileManager(out profileManager);
                if (hr >= 0)
                {
                    // error message: The profile is invalid (0xC00D0BC6)
                    // E.g. no <prx> tags
                    hr = profileManager.LoadProfileByData(profileData, out wmProfile);
                }

                if (profileManager != null)
                {
                    Marshal.ReleaseComObject(profileManager);
                    profileManager = null;
                }

                // Config only if there is a profile retrieved
                if (hr >= 0)
                {
                    // Set the profile on the writer
                    IConfigAsfWriter configWriter = (IConfigAsfWriter)asfWriter;
                    hr = configWriter.ConfigureFilterUsingProfile(wmProfile);
                    if (hr >= 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get asf profile information
        /// </summary>
        /// <returns></returns>
        public bool GetProfileFormatInfo(AsfFormatSelection avformat)
        {
            int hr;
            IWMProfileManager profileManager = null;
            IWMProfile        profile        = null;

            if (this.InnerList.Count > 0)
            {
                // Profile information already loaded
                return(true);
            }

#if DEBUG
            Debug.WriteLine("Look for Windows Media profile information: " + avformat.ToString());
#endif
            try
            {
                IWMProfileManager2        profileManager2        = null;
                IWMProfileManagerLanguage profileManagerLanguage = null;
                WMVersion wmversion   = WMVersion.V4_0;
                int       nbrProfiles = 0;
                int       totalItems  = 0;
                short     langID;

                // Open the profile manager
                try
                {
                    hr = WMLib.WMCreateProfileManager(out profileManager);
                }
                catch (Exception) { hr = -1; }
                if (hr >= 0)
                {
                    // Convert pWMProfileManager to a IWMProfileManager2
                    profileManager2        = profileManager as IWMProfileManager2;
                    profileManagerLanguage = profileManager as IWMProfileManagerLanguage;

                    hr = profileManager2.GetSystemProfileVersion(out wmversion);
#if DEBUG
                    Debug.WriteLine("WM version=" + wmversion.ToString());
#endif

                    hr = profileManagerLanguage.GetUserLanguageID(out langID);
#if DEBUG
                    Debug.WriteLine("WM language ID=" + langID.ToString());
#endif

                    //IWMProfileManagerLanguage
                    // Specify the version number of the profiles to use
                    hr = profileManager2.SetSystemProfileVersion(DefaultWMversion);
                    // Marshal.ThrowExceptionForHR(hr);

                    if (hr >= 0)
                    {
                        hr = profileManager2.GetSystemProfileCount(out nbrProfiles);
                        if (hr < 0)
                        {
                            // No profiles available, so nothing to do
                            return(false);
                        }
#if DEBUG
                        Debug.WriteLine("ProfileCount=" + nbrProfiles.ToString());
#endif
                    }
                    else
                    {
                        // Error occured when setting profile version
                        return(false);
                    }
                }
                else
                {
                    // Error occured when creating profile manager
                    return(false);
                }

                // There are profiles to look for!
                for (int p = 0; (p < nbrProfiles) && (hr >= 0); p++)
                {
                    Guid guid = Guid.Empty;
                    // Load the profile specified by the caller
                    //hr = profileManager2.LoadProfileByID(guid, out profile);
                    // Marshal.ThrowExceptionForHR(hr);
                    hr = profileManager2.LoadSystemProfile(p, out profile);
                    if (hr >= 0)
                    {
                        IWMProfile2 profile2 = profile as IWMProfile2;
                        hr = profile2.GetProfileID(out guid);
#if DEBUG
                        if (hr < 0)
                        {
                            Debug.WriteLine("GetProfileID failed for item " + p.ToString());
                        }
#endif
                    }
#if DEBUG
                    else
                    {
                        Debug.WriteLine("LoadSystemProfile failed for item " + p.ToString());
                    }
#endif
                    if (hr >= 0)
                    {
                        // Add item to list
                        if (AddProfileItem(avformat, profile, guid, null))
                        {
                            totalItems++;
                        }
                    }
                }                 // for p


                // Start of NEW
                // Look for profile (*.prx) files in the current directory.
                // If found, then add the profile(s) to the list
                string profileData;
                string pathProfile   = System.IO.Directory.GetCurrentDirectory();
                string filterProfile = "*.prx";

                // Obtain the file system entries in the directory path.
                string[] directoryEntries =
                    System.IO.Directory.GetFileSystemEntries(pathProfile, filterProfile);

                foreach (string filename in directoryEntries)
                {
                    Debug.WriteLine(filename);
                    if (GetProfileDataFromFile(filename, out profileData))
                    {
                        hr = profileManager.LoadProfileByData(profileData, out profile);
                        if (hr >= 0)
                        {
                            if (AddProfileItem(avformat, profile, Guid.Empty, filename))
                            {
                                totalItems++;
                            }
                        }
                    }
                }
                // End of NEW
            }
            finally
            {
                FindDefaultAsfItem(avformat);

                // Release the locals
                if (profile != null)
                {
                    Marshal.ReleaseComObject(profile);
                    profile = null;
                }
                if (profileManager != null)
                {
                    Marshal.ReleaseComObject(profileManager);
                    profileManager = null;
                }
            }
            return(false);
        }