Ejemplo n.º 1
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

            // set loading function
            Func <Texture2D> loadFromDisk = () => CacheClient.LoadModLogo(modId, locator.GetFileName(), size);

            // set saving function
            Action <Texture2D> saveToDisk = null;

            if (this.storeIfSubscribed)
            {
                saveToDisk = (t) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModLogo(modId, locator.GetFileName(), size, t);
                    }
                };
            }

            // do the work
            this.RequestImage_Internal(locator, size, loadFromDisk, saveToDisk,
                                       onLogoReceived, onFallbackFound, onError);
        }
Ejemplo n.º 2
0
        public static void SaveModLogo(int modId, string fileName,
                                       LogoSize size, Texture2D logoTexture)
        {
            Debug.Assert(modId > 0,
                         "[mod.io] Cannot cache a mod logo without a mod id");
            Debug.Assert(!String.IsNullOrEmpty(fileName),
                         "[mod.io] Cannot cache a mod logo without file name as it"
                         + " is used for versioning purposes");

            string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);

            CacheClient.WritePNGFile(logoFilePath, logoTexture);

            // - Version Info -
            var versionInfo = CacheClient.LoadModLogoVersionInfo(modId);

            if (versionInfo == null)
            {
                versionInfo = new Dictionary <LogoSize, string>();
            }

            versionInfo[size] = fileName;
            CacheClient.WriteJsonObjectFile(GenerateModLogoVersionInfoFilePath(modId),
                                            versionInfo);
        }
Ejemplo n.º 3
0
        public static Texture2D LoadModLogo(int modId, LogoSize size)
        {
            string    logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);
            Texture2D logoTexture  = CacheClient.ReadImageFile(logoFilePath);

            return(logoTexture);
        }
Ejemplo n.º 4
0
        } // Key

        public Image GetImage(LogoSize logoSize, bool noExceptions = true)
        {
            if (!IsSizeAvailable(logoSize))
            {
                throw new NotSupportedException();
            } // if

            var path = Path.Combine(BasePath, PartialPath);
            var filename = Path.Combine(path, GetFilename(logoSize, ".png"));
            try
            {
                return Image.FromFile(filename);
            }
            catch (FileNotFoundException ex)
            {
                if (noExceptions == false)
                {
                    throw new FileNotFoundException(ImageNotFoundExceptionText, ex);
                } // if
            }
            catch (OutOfMemoryException ex)
            {
                if (noExceptions == false)
                {
                    throw new InvalidOperationException(string.Format(ImageLoadExceptionText, filename), ex);
                }
            } // try-catch
            catch
            {
                if (noExceptions == false) throw;
            } // catch

            return GetBrokenFile(logoSize);
        } // GetImage
Ejemplo n.º 5
0
        // ---------[ MOD IMAGES ]---------
        // TODO(@jackson): Look at reconfiguring params
        public static void GetModLogo(ModProfile profile, LogoSize size,
                                      Action <Texture2D> onSuccess,
                                      Action <WebRequestError> onError)
        {
            Debug.Assert(onSuccess != null);

            var logoTexture = CacheClient.LoadModLogo(profile.id, size);

            if (logoTexture != null)
            {
                onSuccess(logoTexture);
            }

            var versionInfo = CacheClient.LoadModLogoVersionInfo(profile.id);

            if (logoTexture == null ||
                versionInfo[size] != profile.logoLocator.GetFileName())
            {
                var textureDownload = DownloadClient.DownloadModLogo(profile, size);

                textureDownload.succeeded += (d) =>
                {
                    CacheClient.SaveModLogo(profile.id, profile.logoLocator.GetFileName(),
                                            size, d.imageTexture);
                };

                textureDownload.succeeded += (d) => onSuccess(d.imageTexture);
                textureDownload.failed    += (d) => onError(d.error);
            }
        }
Ejemplo n.º 6
0
        /// <summary>Stores a mod logo in the cache with the given fileName.</summary>
        public static bool SaveModLogo(int modId, string fileName,
                                       LogoSize size, Texture2D logoTexture)
        {
            Debug.Assert(!String.IsNullOrEmpty(fileName));
            Debug.Assert(logoTexture != null);

            bool   success      = false;
            string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);

            byte[] imageData = logoTexture.EncodeToPNG();

            // write file
            if (LocalDataStorage.WriteFile(logoFilePath, imageData))
            {
                success = true;

                // - Update the versioning info -
                var versionInfo = CacheClient.GetModLogoVersionFileNames(modId);
                if (versionInfo == null)
                {
                    versionInfo = new Dictionary <LogoSize, string>();
                }
                versionInfo[size] = fileName;
                LocalDataStorage.WriteJSONFile(GenerateModLogoVersionInfoFilePath(modId), versionInfo);
            }

            return(success);
        }
Ejemplo n.º 7
0
        } // LogoSizeToSize

        public static string LogoSizeToString(LogoSize logoSize, bool withSize)
        {
            string text;

            switch (logoSize)
            {
                case LogoSize.Size32: text = Properties.Texts.LogoSize32; break;
                case LogoSize.Size48: text = Properties.Texts.LogoSize48; break;
                case LogoSize.Size64: text = Properties.Texts.LogoSize64; break;
                case LogoSize.Size96: text = Properties.Texts.LogoSize96; break;
                case LogoSize.Size128: text = Properties.Texts.LogoSize128; break;
                case LogoSize.Size256: text = Properties.Texts.LogoSize256; break;
                default:
                    throw new IndexOutOfRangeException();
            } // switch

            if (withSize)
            {
                var size = LogoSizeToSize(logoSize);
                return string.Format(Properties.Texts.LogoSizeWithSizeFormat, text, size.Width, size.Height);
            }
            else
            {
                return text;
            } // if-else
        } // LogoSizeToString
Ejemplo n.º 8
0
        } // GetSizeSufix

        protected string GetFilename(LogoSize size, string extension)
        {
            var buffer = new StringBuilder();
            buffer.Append(FilePrefix);
            buffer.Append(GetSizeSufix(size));
            buffer.Append(extension);
            return buffer.ToString();
        } // GetFilename
Ejemplo n.º 9
0
 public static Size LogoSizeToSize(LogoSize logoSize)
 {
     switch (logoSize)
     {
         case LogoSize.Size32: return new Size(32, 32);
         case LogoSize.Size48: return new Size(48, 48);
         case LogoSize.Size64: return new Size(64,64);
         case LogoSize.Size96: return new Size(96,96);
         case LogoSize.Size128: return new Size(128, 128);
         case LogoSize.Size256: return new Size(256, 256);
         default:
             throw new IndexOutOfRangeException();
     } // switch
 } // LogoSizeToSize
Ejemplo n.º 10
0
        } // IsSizeAvailable

        protected virtual string GetSizeSufix(LogoSize logoSize)
        {
            switch (logoSize)
            {
                case LogoSize.Size32: return "@32";
                case LogoSize.Size48: return "@48";
                case LogoSize.Size64: return "@64";
                case LogoSize.Size96: return "@96";
                case LogoSize.Size128: return "@128";
                case LogoSize.Size256: return "@256";
                default:
                    throw new ArgumentOutOfRangeException("LogoSize logoSize");
            } // switch
        } // GetSizeSufix
Ejemplo n.º 11
0
        } // GetLogoIconPath

        public static Image GetBrokenFile(LogoSize logoSize)
        {
            switch (logoSize)
            {
                case LogoSize.Size32: return Properties.Resources.BrokenFile_32;
                case LogoSize.Size48: return Properties.Resources.BrokenFile_48;
                case LogoSize.Size64: return Properties.Resources.BrokenFile_64;
                case LogoSize.Size96: return Properties.Resources.BrokenFile_96;
                case LogoSize.Size128: return Properties.Resources.BrokenFile_128;
                case LogoSize.Size256: return Properties.Resources.BrokenFile_256;
            } // switch

            return null;
        } // GetBrokenFile
Ejemplo n.º 12
0
        /// <summary>Retrieves a mod logo from the cache if it matches the given fileName.</summary>
        public static Texture2D LoadModLogo(int modId, string fileName, LogoSize size)
        {
            Debug.Assert(!String.IsNullOrEmpty(fileName));

            string logoFileName = GetModLogoFileName(modId, size);

            if (logoFileName == fileName)
            {
                return(CacheClient.LoadModLogo(modId, size));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 13
0
        } // GetBrokenFile

        protected virtual bool IsSizeAvailable(LogoSize logoSize)
        {
            switch (logoSize)
            {
                case LogoSize.Size32:
                case LogoSize.Size48:
                case LogoSize.Size64:
                case LogoSize.Size96:
                case LogoSize.Size128:
                case LogoSize.Size256:
                    return true;
                default:
                    return false;
            } // switch
        } // IsSizeAvailable
Ejemplo n.º 14
0
        /// <summary>Retrieves a mod logo from the cache.</summary>
        public static Texture2D LoadModLogo(int modId, LogoSize size)
        {
            string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);

            byte[] imageData;

            if (LocalDataStorage.ReadFile(logoFilePath, out imageData) &&
                imageData != null)
            {
                return(IOUtilities.ParseImageData(imageData));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 15
0
        /// <summary>Retrieves the information for the cached mod logos.</summary>
        public static string GetModLogoFileName(int modId, LogoSize size)
        {
            // - Ensure the logo is the correct version -
            var versionInfo = CacheClient.GetModLogoVersionFileNames(modId);

            if (versionInfo != null)
            {
                string logoFileName = string.Empty;
                if (versionInfo.TryGetValue(size, out logoFileName) &&
                    !String.IsNullOrEmpty(logoFileName))
                {
                    return(logoFileName);
                }
            }
            return(null);
        }
Ejemplo n.º 16
0
        // ---------[ IMAGE DOWNLOADS ]---------
        public static ImageRequest DownloadModLogo(ModProfile profile, LogoSize size)
        {
            ImageRequest request = new ImageRequest();

            request.isDone = false;

            string logoURL = profile.logoLocator.GetSizeURL(size);

            UnityWebRequest webRequest = UnityWebRequest.Get(logoURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            var operation = webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);

            return(request);
        }
Ejemplo n.º 17
0
        /// <summary>Stores a mod logo in the cache with the given fileName.</summary>
        public static bool SaveModLogo(int modId, string fileName,
                                       LogoSize size, Texture2D logoTexture)
        {
            Debug.Assert(!String.IsNullOrEmpty(fileName));
            Debug.Assert(logoTexture != null);

            string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);
            bool   isSuccessful = IOUtilities.WritePNGFile(logoFilePath, logoTexture);

            // - Update the versioning info -
            var versionInfo = CacheClient.GetModLogoVersionFileNames(modId);

            if (versionInfo == null)
            {
                versionInfo = new Dictionary <LogoSize, string>();
            }
            versionInfo[size] = fileName;
            isSuccessful      = (IOUtilities.WriteJsonObjectFile(GenerateModLogoVersionInfoFilePath(modId), versionInfo) &&
                                 isSuccessful);

            return(isSuccessful);
        }
Ejemplo n.º 18
0
        public void DisplayLogo(int modId, LogoImageLocator locator)
        {
            Debug.Assert(locator != null);
            bool     original = m_useOriginal;
            LogoSize size     = (original ? LogoSize.Original : ImageDisplayData.logoThumbnailSize);

            ImageDisplayData displayData = new ImageDisplayData()
            {
                modId            = modId,
                mediaType        = ImageDisplayData.MediaType.ModLogo,
                fileName         = locator.fileName,
                originalTexture  = null,
                thumbnailTexture = null,
            };

            m_data = displayData;

            DisplayLoading();

            ModManager.GetModLogo(displayData.modId,
                                  locator,
                                  size,
                                  (t) =>
            {
                if (!Application.isPlaying)
                {
                    return;
                }

                if (m_data.Equals(displayData))
                {
                    m_data.SetImageTexture(original, t);
                    PresentData();
                }
            },
                                  WebRequestError.LogAsWarning);
        }
Ejemplo n.º 19
0
        public ShortProjectViewModel(string name, string description, string logo, LogoSize size)
        {
            Name        = name;
            Description = description;
            Logo        = logo;

            switch (size)
            {
            case LogoSize.Small:
                Height = 50;
                Width  = 50;
                break;

            case LogoSize.Medium:
                Height = 105;
                Width  = 105;
                break;

            case LogoSize.Wide:
                Height = 215;
                Width  = 215;
                break;
            }
        }
Ejemplo n.º 20
0
        private void MediaPreview_Logo(ImageDisplayComponent display)
        {
            ImageDisplayData imageData = display.data;

            selectedMediaPreview.data = imageData;

            if (imageData.GetImageTexture(selectedMediaPreview.useOriginal) == null)
            {
                bool     original = selectedMediaPreview.useOriginal;
                LogoSize size     = (original ? LogoSize.Original : ImageDisplayData.logoThumbnailSize);

                ModManager.GetModLogo(profile, size,
                                      (t) =>
                {
                    if (Application.isPlaying &&
                        selectedMediaPreview.data.Equals(imageData))
                    {
                        imageData.SetImageTexture(original, t);
                        selectedMediaPreview.data = imageData;
                    }
                },
                                      WebRequestError.LogAsWarning);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Uri to the logo image.
 /// </summary>
 /// <param name="size">The size for the image as required</param>
 /// <returns>The uri to the sized image</returns>
 public Uri Uri(LogoSize size)
 {
     return(Utilities.Extensions.MakeImageUri(size.ToString(), LogoPath));
 }
Ejemplo n.º 22
0
 public static string GenerateModLogoFilePath(int modId, LogoSize size)
 {
     return(GenerateModLogoDirectoryPath(modId)
            + size.ToString() + ".png");
 }
Ejemplo n.º 23
0
 // Start is called before the first frame update
 void Start()
 {
     logosize = GameObject.Find("Logo").GetComponent <LogoSize>();
     btn      = GameObject.Find("StartButton").GetComponent <Button>();
     audio    = GameObject.Find("StartButton").GetComponent <AudioSource>();
 }
Ejemplo n.º 24
0
        } // buttonLoad_Click

        private void comboLogoSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            LogoSize = (LogoSize)comboLogoSize.SelectedIndex;
        } // comboLogoSize_SelectedIndexChanged
Ejemplo n.º 25
0
 /// <summary>Generates the file path for a mod logo.</summary>
 public static string GenerateModLogoFilePath(int modId, LogoSize size)
 {
     return(IOUtilities.CombinePath(GenerateModLogoCollectionDirectoryPath(modId),
                                    size.ToString() + ".png"));
 }
Ejemplo n.º 26
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

            string url      = locator.GetSizeURL(size);
            string fileName = locator.GetFileName();

            // check cache and existing callbacks
            if (this.TryGetCacheOrSetCallbacks(url, onLogoReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onLogoReceived, onError);

            // check for fallback
            callbacks.fallback = this.FindFallbackTexture(locator);

            if (onFallbackFound != null &&
                callbacks.fallback != null)
            {
                onFallbackFound.Invoke(callbacks.fallback);
            }

            // add save function to download callback
            if (this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModLogo(modId, fileName, size, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModLogo(modId, fileName, size, (texture) =>
            {
                if (this == null)
                {
                    return;
                }

                if (texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }
Ejemplo n.º 27
0
        /// <summary>Requests the image for a given ImageDisplayData.</summary>
        public virtual void RequestImageForData(ImageDisplayData data, bool original,
                                                Action <Texture2D> onSuccess,
                                                Action <WebRequestError> onError)
        {
            string url = data.GetImageURL(original);

            // asserts
            Debug.Assert(onSuccess != null);
            Debug.Assert(!string.IsNullOrEmpty(url));

            // create delegates
            Func <Texture2D>   loadFromDisk = null;
            Action <Texture2D> saveToDisk   = null;

            switch (data.descriptor)
            {
            case ImageDescriptor.ModLogo:
            {
                LogoSize size = (original ? LogoSize.Original : ImageDisplayData.logoThumbnailSize);

                loadFromDisk = () => CacheClient.LoadModLogo(data.ownerId, data.imageId, size);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModLogo(data.ownerId, data.imageId, size, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.ModGalleryImage:
            {
                ModGalleryImageSize size = (original
                                                ? ModGalleryImageSize.Original
                                                : ImageDisplayData.galleryThumbnailSize);

                loadFromDisk = () => CacheClient.LoadModGalleryImage(data.ownerId, data.imageId, size);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModGalleryImage(data.ownerId, data.imageId, size, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.YouTubeThumbnail:
            {
                loadFromDisk = () => CacheClient.LoadModYouTubeThumbnail(data.ownerId, data.imageId);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModYouTubeThumbnail(data.ownerId, data.imageId, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.UserAvatar:
            {
                UserAvatarSize size = (original
                                           ? UserAvatarSize.Original
                                           : ImageDisplayData.avatarThumbnailSize);

                loadFromDisk = () => CacheClient.LoadUserAvatar(data.ownerId, size);
            }
            break;
            }

            // request image
            this.RequestImage_Internal(url,
                                       loadFromDisk,
                                       saveToDisk,
                                       onSuccess,
                                       onError);
        }
Ejemplo n.º 28
0
        // ---------[ IMAGE DOWNLOADS ]---------
        public static ImageRequest DownloadModLogo(ModProfile profile, LogoSize size)
        {
            Debug.Assert(profile != null, "[mod.io] Profile parameter cannot be null");

            return(DownloadImage(profile.logoLocator.GetSizeURL(size)));
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Uri to the logo image.
 /// </summary>
 /// <param name="size">The size for the image as required</param>
 /// <returns>The uri to the sized image</returns>
 public Uri Uri(LogoSize size)
 {
     return Utilities.Extensions.MakeImageUri(size.ToString(), LogoPath);
 }
Ejemplo n.º 30
0
        public string GetLogo(int size = 52, LogoSize imageType = LogoSize.Normal)
        {
            if (Image == null)
                return "/Content/Images/nologo.png";

            return imageType == LogoSize.Normal ? Image.Logo : Image.Icon;
        }
 private Uri Uri(LogoSize size)
 {
     return(MakeImageUri(size.ToString(), LogoPath));
 }