Beispiel #1
0
        /// <summary>Retrieves a user's avatar from the cache.</summary>
        public static Texture2D LoadUserAvatar(int userId, UserAvatarSize size)
        {
            string    avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size);
            Texture2D avatarTexture  = IOUtilities.ReadImageFile(avatarFilePath);

            return(avatarTexture);
        }
Beispiel #2
0
        /// <summary>Stores a user's avatar in the cache.</summary>
        public static bool SaveUserAvatar(int userId, UserAvatarSize size,
                                          Texture2D avatarTexture)
        {
            Debug.Assert(avatarTexture != null);

            string avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size);

            return(IOUtilities.WritePNGFile(avatarFilePath, avatarTexture));
        }
Beispiel #3
0
        /// <summary>Requests the user avatar for the given locator.</summary>
        public virtual void RequestUserAvatar(int userId, AvatarImageLocator locator,
                                              UserAvatarSize size,
                                              Action <Texture2D> onAvatarReceived,
                                              Action <Texture2D> onFallbackFound,
                                              Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onAvatarReceived != null);

            string url = locator.GetSizeURL(size);

            if (url == ImageRequestManager.GUEST_AVATAR_URL)
            {
                if (onAvatarReceived != null)
                {
                    onAvatarReceived.Invoke(this.guestAvatar);
                }
                return;
            }

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

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

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

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

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

                if (texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }
        private string GetAvatarPath(UserAvatarSize size)
        {
            if (AvatarPropFlag.Available)
            {
                string s = UserBO.Instance.GetAvatarSizeDirectoryName(size);
                s             = this.AvatarPropFlag.PropData.Replace("{size}", s);
                usePropAvatar = true;
                return(UrlUtil.ResolveUrl(s));
                // return Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar,, this.AvatarPropFlag.PropData);
            }
            usePropAvatar = false;
            //判断头像是否存在,如果存在直接返回头像
            string avatarSrc = AvatarSrc;

            if (string.IsNullOrEmpty(avatarSrc) == false)
            {
#if !Passport
                PassportClientConfig settings = Globals.PassportClient;

                if (settings.EnablePassport)
                {
                    string avatarRelativeUrl = Globals.GetRelativeUrl(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc).Remove(0, 1);
                    return(UrlUtil.JoinUrl(settings.PassportRoot, avatarRelativeUrl));
                }
#endif
                return(Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc));
            }

            //当头像和附加头像都为空时,使用默认头像
            string defaultAvatarUrl;

            switch (size)
            {
            case UserAvatarSize.Small:
                defaultAvatarUrl = Consts.DefaultUserAvatar_Small;
                break;

            case UserAvatarSize.Big:
                defaultAvatarUrl = Consts.DefaultUserAvatar_Big;
                break;

            default:
                defaultAvatarUrl = Consts.DefaultUserAvatar_Default;
                break;
            }

#if !Passport
            PassportClientConfig settings2 = Globals.PassportClient;

            if (settings2.EnablePassport)
            {
                return(UrlUtil.JoinUrl(settings2.PassportRoot, defaultAvatarUrl));
            }
#endif

            return(Globals.GetVirtualPath(SystemDirecotry.Root, defaultAvatarUrl));
        }
Beispiel #5
0
        /// <summary>Stores a user's avatar in the cache.</summary>
        public static bool SaveUserAvatar(int userId, UserAvatarSize size,
                                          Texture2D avatarTexture)
        {
            Debug.Assert(avatarTexture != null);

            string avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size);

            byte[] imageData = avatarTexture.EncodeToPNG();

            return(LocalDataStorage.WriteFile(avatarFilePath, imageData));
        }
Beispiel #6
0
        internal string GetAvatarSizeDirectoryName(UserAvatarSize size)
        {
            switch (size)
            {
            case UserAvatarSize.Big:
                return("B");

            case UserAvatarSize.Small:
                return("S");

            default:
                return("D");
            }
        }
Beispiel #7
0
        /// <summary>Requests the user avatar for the given locator.</summary>
        public virtual void RequestUserAvatar(int userId, AvatarImageLocator locator,
                                              UserAvatarSize size,
                                              Action <Texture2D> onAvatarReceived,
                                              Action <Texture2D> onFallbackFound,
                                              Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onAvatarReceived != null);

            // set loading function
            Func <Texture2D> loadFromDisk = () => CacheClient.LoadUserAvatar(userId, size);

            // do the work
            this.RequestImage_Internal(locator, size, loadFromDisk, null,
                                       onAvatarReceived, onFallbackFound, onError);
        }
Beispiel #8
0
        /// <summary>Retrieves a user's avatar from the cache.</summary>
        public static Texture2D LoadUserAvatar(int userId, UserAvatarSize size)
        {
            string avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size);

            byte[] imageData;

            if (LocalDataStorage.ReadFile(avatarFilePath, out imageData) &&
                imageData != null)
            {
                return(IOUtilities.ParseImageData(imageData));
            }
            else
            {
                return(null);
            }
        }
Beispiel #9
0
        public static ImageRequest DownloadUserAvatar(UserProfile profile,
                                                      UserAvatarSize size)
        {
            Debug.Assert(profile != null, "[mod.io] Profile parameter cannot be null");

            ImageRequest request = null;

            if (profile.avatarLocator == null ||
                String.IsNullOrEmpty(profile.avatarLocator.GetSizeURL(size)))
            {
                Debug.LogWarning("[mod.io] User Profile has no associated avatar information");
            }
            else
            {
                request = DownloadImage(profile.avatarLocator.GetSizeURL(size));
            }

            return(request);
        }
        private string OutputImage(string url, UserAvatarSize size)
        {
            int width, height;

            switch (size)
            {
            case UserAvatarSize.Big:
                width  = 120;
                height = 120;
                break;

            case UserAvatarSize.Small:
                width  = 24;
                height = 24;
                break;

            default:
                width  = 48;
                height = 48;
                break;
            }
            return(string.Format(imageFormat, HttpUtility.HtmlAttributeEncode(url), width, height));
        }
Beispiel #11
0
        // ---------[ UI FUNCTIONALITY ]---------
        public void DisplayAvatar(int userId, AvatarImageLocator locator)
        {
            Debug.Assert(locator != null);
            bool           original = m_useOriginal;
            UserAvatarSize size     = (original ? UserAvatarSize.Original : ImageDisplayData.avatarThumbnailSize);

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

            m_data = displayData;

            DisplayLoading();

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

                if (m_data.Equals(displayData))
                {
                    m_data.SetImageTexture(original, t);
                    PresentData();
                }
            },
                                     WebRequestError.LogAsWarning);
        }
Beispiel #12
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);
        }
Beispiel #13
0
 /// <summary>Generates the file path for a user's profile.</summary>
 public static string GenerateUserAvatarFilePath(int userId, UserAvatarSize size)
 {
     return(IOUtilities.CombinePath(CacheClient.GenerateUserAvatarDirectoryPath(userId),
                                    size.ToString() + ".png"));
 }
 private string OutputImage(string url, UserAvatarSize size)
 {
     int width, height;
     switch (size)
     {
         case UserAvatarSize.Big:
             width = 120;
             height = 120;
             break;
         case UserAvatarSize.Small:
             width = 24;
             height = 24;
             break;
         default:
             width = 48;
             height = 48;
             break;
     }
     return string.Format(imageFormat, HttpUtility.HtmlAttributeEncode(url), width, height);
 }
        private string GetAvatarPath(UserAvatarSize size)
        {
            if (AvatarPropFlag.Available)
            {
                string s =  UserBO.Instance.GetAvatarSizeDirectoryName(size);
                s = this.AvatarPropFlag.PropData.Replace("{size}",s);
                usePropAvatar = true;
                return UrlUtil.ResolveUrl(s);
               // return Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar,, this.AvatarPropFlag.PropData);
            }
            usePropAvatar = false;
            //判断头像是否存在,如果存在直接返回头像
            string avatarSrc = AvatarSrc;

            if (string.IsNullOrEmpty(avatarSrc) == false)
            {
#if !Passport
                PassportClientConfig settings = Globals.PassportClient;

                if (settings.EnablePassport)
                {
                    string avatarRelativeUrl = Globals.GetRelativeUrl(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc).Remove(0, 1);
                    return UrlUtil.JoinUrl(settings.PassportRoot, avatarRelativeUrl);
                }
#endif
                return Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc);
            }

            //当头像和附加头像都为空时,使用默认头像
            string defaultAvatarUrl;

            switch (size)
            {
                case UserAvatarSize.Small:
                    defaultAvatarUrl = Consts.DefaultUserAvatar_Small;
                    break;

                case UserAvatarSize.Big:
                    defaultAvatarUrl = Consts.DefaultUserAvatar_Big;
                    break;

                default:
                    defaultAvatarUrl = Consts.DefaultUserAvatar_Default;
                    break;
            }

#if !Passport
            PassportClientConfig settings2 = Globals.PassportClient;

            if (settings2.EnablePassport)
                return UrlUtil.JoinUrl(settings2.PassportRoot, defaultAvatarUrl);
#endif

            return Globals.GetVirtualPath(SystemDirecotry.Root, defaultAvatarUrl);

        }
Beispiel #16
0
        private string GetAvatarPhysicalPath(int userID, UserAvatarSize size, string src)
        {
            string t = UserBO.Instance.GetAvatarSizeDirectoryName(size);

            return(Globals.GetPath(SystemDirecotry.Upload_Avatar, t, src));
        }