Exemplo n.º 1
0
        public LimePerson(string name, string[] roles)
        {
            LimeLib.LifeTrace(this);

            Name  = name;
            Roles = roles;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Construct the class by copying from another object.
 /// </summary>
 /// <param name="attr">base attribute to copy to the new one</param>
 public LimePropertyAttribute(LimePropertyAttribute attr)
 {
     if (attr != null)
     {
         LimeLib.CopyPropertyValues(attr, this);
     }
 }
Exemplo n.º 3
0
        public LimePerson(int id, string name, string[] roles)
        {
            LimeLib.LifeTrace(this);

            TmdbId = id;
            Name   = name;
            Roles  = roles;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Duplicate a LimeCommand, and enable to make it a Toggle comand
        /// </summary>
        /// <param name="copy">Source command to copy</param>
        /// <param name="toggle">enable to create a Toggle command</param>
        public LimeCommand(LimeCommand copy, bool toggle)
        {
            // Copy properties
            LimeLib.CopyPropertyValues(copy, this);
            ToggleCmdName = copy.ToggleCmdName;
            _ToggleCmd    = copy._ToggleCmd;

            // Convert to Toggle command
            AlwaysToggle = (copy.IsToggle && toggle);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parameterless constructor to enable Xaml
        /// </summary>
        public LimeProperty()
        {
            LimeLib.LifeTrace(this);

            Source = null;
            PInfo  = null;
            Type   = null;
            Ident  = null;
            Name   = null;
            Desc   = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Try to save the Person data to the local database.
        /// </summary>
        public void Save()
        {
            if (IsBusy)
            {
                return;
            }
            if (string.IsNullOrEmpty(Name))
            {
                return;
            }

            // Make filename from person name
            string path    = null;
            string localDb = LimeLib.ResolvePath(LocalDbPath);

            if (localDb != null)
            {
                var name = Name;

                // Remove characters forbidden in filenames
                string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
                foreach (char c in invalid)
                {
                    name = name.Replace(c.ToString(), "");
                }

                path = Path.Combine(localDb, name + Extension);
            }

            try
            {
                IsSaving = true;
                LimeMsg.Debug("Person SaveAsync: {0}", Name);
                using (Stream file = File.Open(path, FileMode.Create))
                {
                    ZeroFormatterSerializer.Serialize(file, this);
                }
            }
            catch
            {
                LimeMsg.Error("UnableFileDir", path);
            }
            finally
            {
                IsSaving = false;
                IsLoaded = true;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Build a cover from the Jumbo icon of a file/directory
        /// </summary>
        /// <param name="path">path to the file</param>
        /// <returns>Pictures image</returns>
        public void BuildCover(string path)
        {
            LimeMsg.Debug("LimeMetadata BuildCover: path: {0}", path);
            ImageSource ret = null;

            try
            {
                LimeItem item = new LimeItem(path);
                using (var bmp = item.Bitmap(256))
                {
                    ret = LimeLib.ImageSourceFrom(bmp);
                }
            }
            catch
            {
                LimeMsg.Debug("LimeMetadata BuildCover: Failed: path: {0}", path);
            }

            Pictures = ret;
        }
Exemplo n.º 8
0
        // --------------------------------------------------------------------------------------------------
        #region ctors


        /// <summary>
        /// Construct a reference to a property in a class
        /// </summary>
        /// <param name="ident">identifier of the LimeProperty</param>
        /// <param name="source">Parent object of the class where the property belongs</param>
        /// <param name="pi">PropertyInfo of the property (null if not referenced)</param>
        /// <param name="attr">Configuration attributes attached to this property</param>
        /// <param name="name">User-friendly name of the object. Automatically taken from translation by default.</param>
        /// <param name="readOnly">Define readOnly attribute</param>
        /// <param name="visible">Define visibility to the user</param>
        private void Factory(string ident, object source, PropertyInfo pi, LimePropertyAttribute attr, string name = null, bool?readOnly = null, bool?visible = null)
        {
            LimeLib.LifeTrace(this);

            Source = source;
            string languageSection = IniLanguageSection;

            if (pi != null)
            {
                // Referenced source
                PInfo = pi;
                var vobj = pi.GetValue(Source);
                Type = vobj != null?vobj.GetType() : pi.PropertyType;

                Ident = ident ?? pi.Name;
            }
            else
            {
                // Unreferenced source
                Type  = source.GetType();
                Ident = ident;
            }

            // Implied attributes
            if (source is System.Windows.Input.ICommand)
            {
                ReadOnly        = true;
                languageSection = IniLanguageCommand;
            }

            // Copy attribute
            if (attr != null)
            {
                if (attr.GetType() != typeof(LimePropertyAttribute))
                {
                    attr = new LimePropertyAttribute(attr);
                }
                LimeLib.CopyPropertyValues(attr, this);
            }

            // Forced attributes
            if (readOnly != null)
            {
                ReadOnly = readOnly == true;
            }
            if (visible != null)
            {
                Visible = visible == true;
            }


            // Bind the object
            if (source is INotifyPropertyChanged src)
            {
                //LimeMsg.Debug("LimeProperty Factory: Subscribe {0} / {1}", Ident, src);
                src.PropertyChanged += SourcePropertyChanged;
            }

            if (Ident == null || name != null || !Visible)
            {
                Name = name ?? ident;
                Desc = null;
            }
            else
            {
                // Retrieve properties from LimeLanguage
                Name = LimeLanguage.Translate(languageSection, Ident + ".name", Ident);
                Desc = LimeLanguage.Translate(languageSection, Ident + ".desc", Name);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Construct and retrieve Metadata from a directory/file path
        /// </summary>
        /// <param name="item">The <see cref="LimeItem"/> element to construct Metadata for.</param>
        /// <param name="coverOnly">Try to load only a cover, not the system icon</param>
        public LimeMetadata(LimeItem item, bool coverOnly) : this()
        {
            LimeLib.LifeTrace(this);

            // Disable modification detection
            _Modified = null;


            LimeMsg.Debug("LimeMetadata: {0}", item.Name);
            string path = item.Path;

            if (!coverOnly)
            {
                // Add Name
                Add("Name", item.Name, true, false);
                if (item.Link != null)
                {
                    // Link
                    path = item.Link;
                    Add("LinkLabel");
                }

                // Handle tasks
                if (item.Task)
                {
                    Add("Task", item.Name, true);
                }

                // Display path
                Add("Path", item, "Path", readOnly: item.Task);
            }

            // Retrieve Tags
            if (!item.Task && !item.Directory && !LimeLib.IsPIDL(path) && !LimeLib.IsSSPD(path))
            {
                LimeMsg.Debug("LimeMetadata: TagLib: {0}", item.Name);
                try
                {
                    TagLibFile = TagLib.File.Create(path, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy);
                }
                catch
                {
                    LimeMsg.Debug("LimeMetadata: {0}: Failed TagLib.File.Create({1})", item.Name, path);
                }
            }

            // Extract Tags
            if (TagLibFile != null)
            {
                LimeMsg.Debug("LimeMetadata: TagLib done: {0}", item.Name);

                // Retrieve Type
                if (TagLibFile.Properties != null && TagLibFile.Properties.Codecs != null)
                {
                    TagLib.MediaTypes[] prioTypes = new TagLib.MediaTypes[] {
                        TagLib.MediaTypes.Video, TagLib.MediaTypes.Audio, TagLib.MediaTypes.Photo, TagLib.MediaTypes.Text
                    };

                    var codecs = TagLibFile.Properties.Codecs;
                    foreach (var codec in codecs)
                    {
                        if (codec != null)
                        {
                            TagLib.MediaTypes mask = codec.MediaTypes | (TagLib.MediaTypes)Type;

                            foreach (var typ in prioTypes)
                            {
                                if ((mask & typ) != 0)
                                {
                                    Type = (MediaType)typ;
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (TagLibFile is TagLib.Image.NoMetadata.File)
                {
                    Type = MediaType.Image;
                }
            }

            // Handle Links
            if (!coverOnly && item.Link != null)
            {
                using (var link = new ShellShortcut(item.Path))
                {
                    Add("LinkWorkdir", link.WorkingDirectory);
                    //Add("LinkKey", link.Hotkey);
                    Add("LinkWindowStyle", (ShellLinkWindowStyle)link.WindowStyle);

                    if (Type == MediaType.None)
                    {
                        Add("LinkArguments", link.Arguments);
                    }

                    Add("LinkComment", link.Description);
                }


                Add("TagLabel");

                // Target Path
                if (LimeLib.IsPIDL(item.Link))
                {
                    // Retrieve name of the PIDL
                    try
                    {
                        var dInfo = new DirectoryInfoEx(new ShellDll.PIDL(LimeLib.GetPIDL(item.Link), true));
                        Add("LinkTarget", dInfo.Label, true);
                    }
                    catch { }
                }
                else
                {
                    Add("LinkTarget", item.Link, LimeLib.IsSSPD(item.Link));
                }
            }


            if (TagLibFile != null)
            {
                LimeMsg.Debug("LimeMetadata: TagLib done 2: {0}", item.Name);
                // Build the Properties
                BuildProperties();


                // Build the Pictures image
                BuildCover(coverOnly);
            }
            else if (!coverOnly)
            {
                // Build the Pictures image from the file icon
                using (var bmp = item.Bitmap(256))
                {
                    Pictures = LimeLib.ImageSourceFrom(bmp);
                }
            }

            if (!coverOnly)
            {
                // Finalize
                BuildToolTip();
            }

            // re-enable modification detection
            _Modified = false;
            LimeMsg.Debug("LimeMetadata End: {0}", item.Name);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Try to retrieve the Person data from the local database, or Internet
        /// </summary>
        /// <returns>true if successful (false if not found)</returns>
        public bool Load()
        {
            if (IsLoading || IsSaving || IsLoaded)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(Name))
            {
                return(false);
            }


            // Make filename from person name
            string path    = null;
            string localDb = LimeLib.ResolvePath(LocalDbPath);

            if (localDb != null)
            {
                var name = Name;

                // Remove characters forbidden in filenames
                string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
                foreach (char c in invalid)
                {
                    name = name.Replace(c.ToString(), "");
                }

                path = Path.Combine(localDb, name + Extension);
            }

            try
            {
                IsLoading = true;

                if (File.Exists(path))
                {
                    LimePerson lp;
                    // Local Database
                    using (Stream file = File.Open(path, FileMode.Open))
                    {
                        lp = ZeroFormatterSerializer.Deserialize <LimePerson>(file);
                    }

                    // Properties to be preserved
                    var roles         = Roles;
                    var rolesReadOnly = RolesReadOnly;

                    // Copy properties
                    LimeLib.CopyPropertyValues(lp, this);

                    // Restore Properties to be preserved
                    Roles         = roles;
                    RolesReadOnly = rolesReadOnly;

                    // Done
                    IsLoaded = true;
                    return(true);
                }
            }
            catch
            {
                LimeMsg.Error("UnableFileDir", path);
            }
            finally
            {
                IsLoading = false;
            }

            if (IsDownloading && MetaSearch != null)
            {
                bool ret = false;
                try
                {
                    IsLoading = true;
                    LimeMsg.Debug("Person Load: Download {0}", Name);
                    ret = MetaSearch.GetPersonAsync(this).Result;
                }
                catch
                {
                    LimeMsg.Error("ErrPersonDownload", Name);
                }
                finally
                {
                    IsLoading     = false;
                    IsDownloading = false;
                }

                IsLoaded = true;

                if (ret && AutoSave)
                {
                    Save();
                }

                return(ret);
            }

            return(false);
        }
Exemplo n.º 11
0
        public LimePerson(string namerole)
        {
            LimeLib.LifeTrace(this);

            FromString(namerole, CultureInfo.CurrentCulture);
        }
Exemplo n.º 12
0
        // --------------------------------------------------------------------------------------------------
        #region ctors

        public LimePerson()
        {
            LimeLib.LifeTrace(this);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Convert a TagLib IPicture to a LimePicture
 /// </summary>
 /// <param name="pic">IPicture source to copy</param>
 public LimePicture(IPicture pic)
 {
     LimeLib.CopyPropertyValues(pic, this);
 }
Exemplo n.º 14
0
        // --------------------------------------------------------------------------------------------------
        #region ctors

        /// <summary>
        /// Parameterless constructor
        /// </summary>
        public LimePicture()
        {
            LimeLib.LifeTrace(this);
        }