Exemple #1
0
        private void ClearRelatedValues()
        {
            if (PropertyId == default(int))
            {
                return;
            }

            if (UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties.Any())
            {
                var uploadFieldConfigNode =
                    UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties.FirstOrDefault(x => x.Alias == PropertyTypeAlias);
                if (uploadFieldConfigNode != null)
                {
                    // get the current document
                    //Content legacy = Content.GetContentFromVersion(Version);
                    EnsureLoadedContentItem(Version);

                    var prop = LoadedContentItem.getProperty(uploadFieldConfigNode.WidthFieldAlias);
                    if (prop != null)
                    {
                        prop.Value = String.Empty;
                    }

                    prop = LoadedContentItem.getProperty(uploadFieldConfigNode.HeightFieldAlias);
                    if (prop != null)
                    {
                        prop.Value = String.Empty;
                    }

                    prop = LoadedContentItem.getProperty(uploadFieldConfigNode.LengthFieldAlias);
                    if (prop != null)
                    {
                        prop.Value = String.Empty;
                    }

                    prop = LoadedContentItem.getProperty(uploadFieldConfigNode.ExtensionFieldAlias);
                    if (prop != null)
                    {
                        prop.Value = String.Empty;
                    }
                }
            }
        }
Exemple #2
0
        public static bool LoadUserShow(UserShowDef userShow, bool addToDefDatabase = true)
        {
            // Get images in path
            IEnumerable <string> filePaths = Enumerable.Empty <string>();

            if (!Directory.Exists(userShow.path))
            {
                Log.Message($"RimFlix {userShow.defName} : {userShow.label}: Path <{userShow.path}> does not exist.");
                return(false);
            }
            try
            {
                DirectoryInfo dirInfo = new DirectoryInfo(userShow.path);
                filePaths = from file in dirInfo.GetFiles()
                            where file.Name.ToLower().EndsWith(".jpg") || file.Name.ToLower().EndsWith(".png")
                            where (file.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden
                            select file.FullName;
            }
            catch
            {
                Log.Message($"RimFlix {userShow.defName} : {userShow.label}: Error trying to load files from <{userShow.path}>.");
                return(false);
            }
            if (!filePaths.Any())
            {
                Log.Message($"RimFlix {userShow.defName} : {userShow.label}: No images found in <{userShow.path}>.");
                // User may want to keep a show with an empty directory for future use.
                //return false;
            }

            // Load textures for images
            userShow.frames = new List <GraphicData>();
            foreach (string filePath in filePaths)
            {
                // RimWorld sets internalPath to filePath without extension
                // This causes problems with files that have same name but different extension (file.jpg, file.png)
                string internalPath = filePath.Replace('\\', '/');
                if (!RimFlixContent.contentList.ContainsKey(internalPath))
                {
                    string      path        = Path.GetDirectoryName(filePath);
                    string      file        = Path.GetFileName(filePath);
                    VirtualFile virtualFile = AbstractFilesystem.GetDirectory(path).GetFile(file);
                    LoadedContentItem <Texture2D> loadedContentItem = ModContentLoader <Texture2D> .LoadItem(virtualFile);

                    RimFlixContent.contentList.Add(internalPath, loadedContentItem.contentItem);
                }
                userShow.frames.Add(new GraphicData
                {
                    texPath      = internalPath,
                    graphicClass = typeof(Graphic_Single)
                });
            }

            // Create televisionDefs list
            userShow.televisionDefs = new List <ThingDef>();
            foreach (string televisionDefString in userShow.televisionDefStrings)
            {
                userShow.televisionDefs.Add(ThingDef.Named(televisionDefString));
            }

            // Add user show to def database
            if (!DefDatabase <ShowDef> .AllDefs.Contains(userShow))
            {
                DefDatabase <ShowDef> .Add(userShow);
            }
            return(true);
        }