Ejemplo n.º 1
0
 public TimeSpan?GetDuration(string filePath)
 {
     try
     {
         using (ShellObject shell = ShellObject.FromParsingName(filePath))
         {
             IShellProperty prop  = shell.Properties.System.Media.Duration;
             var            value = prop.ValueAsObject;
             return(TimeSpan.FromTicks((long)(ulong)value));
             // Duration will be formatted as 00:44:08
             //string duration = prop.FormatForDisplay(PropertyDescriptionFormatOptions.None);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         try
         {
             IWMPMedia mediainfo = _wmp.newMedia(filePath);
             var       duration  = mediainfo.duration;
             if (duration < double.Epsilon)
             {
                 return(null);
             }
             return(TimeSpan.FromSeconds(duration));
         }
         catch (Exception e2)
         {
             Debug.WriteLine(e);
             return(null);
         }
         return(null);
     }
 }
        /// <summary>
        /// Controles of het een volledige radiosessie is
        /// </summary>
        /// <param name="localpath"></param>
        /// <returns></returns>
        private bool IsFullSession(string localpath)
        {
            try
            {
                //Lengte van setje opvragen.
                ulong ticks = 0;
                using (ShellObject shell = ShellObject.FromParsingName(localpath))
                {
                    IShellProperty prop = shell.Properties.System.Media.Duration;
                    if (prop.ValueAsObject is null)
                    {
                        return(false);//Is nog niet compleet
                    }
                    else
                    {
                        ticks = (ulong)prop.ValueAsObject;
                    }
                }

                //Kijken of het een volledige sessie is
                if (ticks > 108000000000) //3 uur lengte
                {
                    return(true);         //Het is een volledige sessie.
                }

                return(false);//De sessie is nog niet compleet
            }
            catch (Exception ex)
            {
                Console.WriteLine("GetLengthUsingShellObject failed: " + ex.Message);

                return(false);//Er is iets misgelopen, de sessie is waarschijnlijk niet compleet
            }
        }
Ejemplo n.º 3
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireExtHasHandler();

            const string cval         = "bcomment??";
            string       propertyName = "System.Comment";

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            var handler = new CPropertyHandler();

            handler.Initialize(fileName, 0);

            PropVariant value = new PropVariant(cval);

            handler.SetValue(new TestDriverCodePack.PropertyKey(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 6), value);
            handler.Commit();

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // Use API Code Pack to read the value
            IShellProperty prop = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName);
            object         oval = prop.ValueAsObject;

            File.Delete(fileName);  // only works if all have let go of the file

            return((string)oval == cval);
        }
Ejemplo n.º 4
0
        public static string[] GetAllInfo(string filePath)
        {
            using (var shell = ShellObject.FromParsingName(filePath))
            {
                // title
                IShellProperty titleProp = shell.Properties.System.Title;
                var            title     = (string)titleProp.ValueAsObject;

                // artist
                IShellProperty artistProp = shell.Properties.System.Music.DisplayArtist;
                var            artist     = (string)artistProp.ValueAsObject;

                // album
                IShellProperty albumProp = shell.Properties.System.Music.AlbumTitle;
                var            album     = (string)albumProp.ValueAsObject;

                // duration
                IShellProperty durationProp = shell.Properties.System.Media.Duration;
                var            duration     = (ulong)durationProp.ValueAsObject;

                return(new string[]
                {
                    title,
                    artist,
                    album,
                    TimeSpan.FromTicks((long)duration).ToString(@"mm\:ss")
                });
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the duration as nano seconds.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static long GetDurationAsNanoSeconds(string filePath)
        {
            Logger.Info("DurationProvier:GetDurationAsNanoSeconds", "Calculating video file duration");
            long duration;

            try
            {
                using (ShellObject shell = ShellObject.FromParsingName(filePath))
                {
                    IShellProperty prop = shell.Properties.System.Media.Duration; // in 100-nanoseconds unit
                    if (prop == null || prop.ValueAsObject == null)
                    {
                        return(0);
                    }
                    string nb = prop.ValueAsObject.ToString();
                    if (long.TryParse(nb, out duration))
                    {
                        return(duration * 100);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Error("DurationProvier:GetDurationAsNanoSeconds", "Unable to calculate file duration: " + exception.Message);
            }
            return(0);
        }
Ejemplo n.º 6
0
 private static string GetValue(IShellProperty value)
 {
     if (value == null || value.ValueAsObject == null)
     {
         return String.Empty;
     }
     return value.ValueAsObject.ToString();
 }
Ejemplo n.º 7
0
 private static double GetWindowsAPIDurationValue(IShellProperty value)
 {
     if (value == null || value.ValueAsObject == null)
     {
         return(0);
     }
     // Divide the value by 10000 to convert it into a timespan using FromMilliseconds
     return(Convert.ToDouble(value.ValueAsObject.ToString()) / 10000);
 }
Ejemplo n.º 8
0
    public static uint?GetNumber(IShellProperty value)
    {
        if (value == null || value.ValueAsObject == null)
        {
            return(null);
        }

        return((uint?)value.ValueAsObject);
    }
Ejemplo n.º 9
0
 public static double GetDurationMs(string filePath)
 {
     using (var shell = ShellObject.FromParsingName(filePath))
     {
         IShellProperty prop        = shell.Properties.System.Media.Duration;
         var            length100Ns = (ulong)prop.ValueAsObject;
         return(length100Ns / 10000);
     }
 }
Ejemplo n.º 10
0
        public bool IsBitlockerEnabledOnSystemDrive()
        {
            string         systemDrive = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
            IShellProperty prop        = ShellObject.FromParsingName(systemDrive).Properties.GetProperty("System.Volume.BitLockerProtection");
            int?           bitLockerProtectionStatus = (prop as ShellProperty <int?>).Value;

            return(bitLockerProtectionStatus.HasValue &&
                   (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5));
        }
Ejemplo n.º 11
0
 public static int GetFrameWidth(this FileInfo movieFile)
 {
     using (ShellObject shell = ShellObject.FromParsingName(movieFile.FullName))
     {
         IShellProperty prop        = shell.Properties.System.Video.FrameWidth;
         string         returnValue = prop.FormatForDisplay(PropertyDescriptionFormatOptions.None);
         return(int.TryParse(returnValue, out int value) ? value : -1);
     }
 }
Ejemplo n.º 12
0
    public static string[] GetValues(IShellProperty value)
    {
        if (value == null || value.ValueAsObject == null)
        {
            return(null);
        }

        return((string[])value.ValueAsObject);
    }
Ejemplo n.º 13
0
 private static TimeSpan GetMediaDuration(string mediaFile)
 {
     using (var shell = ShellObject.FromParsingName(mediaFile))
     {
         IShellProperty prop = shell.Properties.System.Media.Duration;
         var            t    = (ulong)prop.ValueAsObject;
         // need to handle this error
         return(TimeSpan.FromTicks((long)t));
     }
 }
        private static string GetVideoDuration(string filePath)
        {
            string         applicationPath = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
            string         appPath         = applicationPath.Replace("\\", "/");
            ShellFile      so   = ShellFile.FromFilePath(filePath);
            IShellProperty prop = so.Properties.System.Media.Duration;
            var            u    = (ulong)prop.ValueAsObject;

            return(TimeSpan.FromTicks((long)u).ToString());
        }
Ejemplo n.º 15
0
        private static FilePropertyGroup GetGroup(IShellProperty shellProperty)
        {
            var split = shellProperty.CanonicalName.Split('.');

            if (split.Length >= 3 && Enum.TryParse(split[1], true, out FilePropertyGroup group))
            {
                return(group);
            }

            return(FilePropertyGroup.Details);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// This method tries to get the string representation of an property object.
 /// </summary>
 private static string getStringPropertyValue(IShellProperty property)
 {
     try
     {
         return(property.ValueAsObject.ToString());
     }
     catch
     {
         return("Error: Unable to print this property as a text.");
     }
 }
Ejemplo n.º 17
0
        private void GetVideoDuration()
        {
            TimeSpan ts; //use Windows API Codepack to determine the length of the video

            using (var shell = ShellObject.FromParsingName(VideoPath)) {
                IShellProperty prop = shell.Properties.System.Media.Duration;
                var            t    = (ulong)prop.ValueAsObject;
                ts            = TimeSpan.FromTicks((long)t);
                VideoDuration = ParseDuration(ts.ToString());
            }
        }
Ejemplo n.º 18
0
 public void Add(IShellProperty p)
 {
     if (p.CanonicalName != null)
     {
         Properties.Add(new Property
         {
             Name  = p.CanonicalName,
             Value = p.FormatForDisplay(PropertyDescriptionFormatOptions.None)
         });
     }
 }
Ejemplo n.º 19
0
 private static TimeSpan GetDuration(string filePath)
 {
     using (var shell = ShellObject.FromParsingName(filePath))
     {
         ulong          t    = 0;
         IShellProperty prop = shell.Properties.System.Media.Duration;
         if (prop.ValueAsObject != null)
         {
             t = (ulong)prop.ValueAsObject;
         }
         return(TimeSpan.FromTicks((long)t));
     }
 }
Ejemplo n.º 20
0
        public static bool CheckBitLockerIsOn(string disk)
        {
            IShellProperty prop = ShellObject.FromParsingName(disk).Properties.GetProperty("System.Volume.BitLockerProtection");
            int?           bitLockerProtectionStatus = (prop as ShellProperty <int?>).Value;

            if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 21
0
 static void SetPropertyValue(IShellProperty prop, object value)
 {
     if (prop.ValueType == typeof(string[]))        //只读属性不会改变,故与实际类型不符的只有string[]这一种
     {
         string[] values = (value as string).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
         (prop as ShellProperty<string[]>).Value = values;
     }
     if (prop.ValueType == typeof(string))
     {
         (prop as ShellProperty<string>).Value = value as string;
     }
     else if (prop.ValueType == typeof(ushort?))
     {
         (prop as ShellProperty<ushort?>).Value = value as ushort?;
     }
     else if (prop.ValueType == typeof(short?))
     {
         (prop as ShellProperty<short?>).Value = value as short?;
     }
     else if (prop.ValueType == typeof(uint?))
     {
         (prop as ShellProperty<uint?>).Value = value as uint?;
     }
     else if (prop.ValueType == typeof(int?))
     {
         (prop as ShellProperty<int?>).Value = value as int?;
     }
     else if (prop.ValueType == typeof(ulong?))
     {
         (prop as ShellProperty<ulong?>).Value = value as ulong?;
     }
     else if (prop.ValueType == typeof(long?))
     {
         (prop as ShellProperty<long?>).Value = value as long?;
     }
     else if (prop.ValueType == typeof(DateTime?))
     {
         (prop as ShellProperty<DateTime?>).Value = value as DateTime?;
     }
     else if (prop.ValueType == typeof(double?))
     {
         (prop as ShellProperty<double?>).Value = value as double?;
     }
 }
Ejemplo n.º 22
0
 private static void SetPropertyValue(string value, IShellProperty prop)
 {
     if (prop.ValueType == typeof(string[]))
     {
         string [] values = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
         (prop as ShellProperty<string[]>).Value = values;
     }
     if (prop.ValueType == typeof(string))
     {
         (prop as ShellProperty<string>).Value = value;
     }
     else if (prop.ValueType == typeof(ushort?))
     {
         (prop as ShellProperty<ushort?>).Value = ushort.Parse(value);
     }
     else if (prop.ValueType == typeof(short?))
     {
         (prop as ShellProperty<short?>).Value = short.Parse(value);
     }
     else if (prop.ValueType == typeof(uint?))
     {
         (prop as ShellProperty<uint?>).Value = uint.Parse(value);
     }
     else if (prop.ValueType == typeof(int?))
     {
         (prop as ShellProperty<int?>).Value = int.Parse(value);
     }
     else if (prop.ValueType == typeof(ulong?))
     {
         (prop as ShellProperty<ulong?>).Value = ulong.Parse(value);
     }
     else if (prop.ValueType == typeof(long?))
     {
         (prop as ShellProperty<long?>).Value = long.Parse(value);
     }
     else if (prop.ValueType == typeof(DateTime?))
     {
         (prop as ShellProperty<DateTime?>).Value = DateTime.Parse(value);
     }
     else if (prop.ValueType == typeof(double?))
     {
         (prop as ShellProperty<double?>).Value = double.Parse(value);
     }
 }
Ejemplo n.º 23
0
        private static void DisplayPropertyValue(IShellProperty prop)
        {
            string value = string.Empty;
            value = prop.ValueAsObject == null ? "" : prop.FormatForDisplay(
                    PropertyDescriptionFormat.Default);

            Console.WriteLine("{0} = {1}", prop.CanonicalName, value);
        }