// ---------[ 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); }
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); }
public static Texture2D LoadModLogo(int modId, LogoSize size) { string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); Texture2D logoTexture = CacheClient.ReadImageFile(logoFilePath); return(logoTexture); }
} // 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
// ---------[ 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); } }
/// <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); }
} // 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
} // 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
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
} // 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
} // 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
/// <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); } }
} // 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
/// <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); } }
/// <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); }
// ---------[ 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); }
/// <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); }
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); }
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; } }
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); } }
/// <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)); }
public static string GenerateModLogoFilePath(int modId, LogoSize size) { return(GenerateModLogoDirectoryPath(modId) + size.ToString() + ".png"); }
// 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>(); }
} // buttonLoad_Click private void comboLogoSize_SelectedIndexChanged(object sender, EventArgs e) { LogoSize = (LogoSize)comboLogoSize.SelectedIndex; } // comboLogoSize_SelectedIndexChanged
/// <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")); }
// ---------[ 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); } }); }
/// <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); }
// ---------[ 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))); }
/// <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); }
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)); }