예제 #1
0
        private static GraphicArchive Load(FileStream path)
        {
            using (BinaryReader br = new BinaryReader(path, Encoding.Unicode))
            {
                while (br.ReadByte() != Constants.HeaderTextTerminator)
                {
                }
                byte[] read = br.ReadBytes(3);
                if (read[0] != 85 || read[1] != 90 || read[2] != 88)                 // 'UZX' as ASCII characters
                {
                    throw new InvalidDataException("wrong identification string");
                }
                byte zoomFactor = (byte)(br.ReadByte() - 48);                 // zoomFactor number is stored as ASCII. -48 will 'convert' this to int
                int  elementNumber;
                List <ArchiveElement> graphics = new List <ArchiveElement>();
                while (true)
                {
                    elementNumber = br.ReadInt32();
                    if (elementNumber == -1)
                    {
                        break;
                    }
                    br.ReadInt32();                                                                                       //skipping data (bauform)
                    br.ReadInt32();                                                                                       //skipping data (fwSig)
                    int            animationPhase = br.ReadInt32();                                                       //AnimationPhase
                    int            alternative    = br.ReadInt32();                                                       //Alternative
                    ArchiveElement archiveElement = new ArchiveElement(elementNumber, animationPhase, alternative, null); //Graphic loaded later
                    archiveElement.SeekPosition = ((int)(br.BaseStream.Position + 4 + br.ReadInt32()));                   // +4 Used for unknown reasons. Possibly because of C/C# incompatibility
                    graphics.Add(archiveElement);
                }
                foreach (var item in graphics)
                {
                    br.BaseStream.Seek(item.SeekPosition + sizeof(int) * 7, SeekOrigin.Begin);                     // sizeof(int) * 7 => Skip 7 integer-sized fields
                    item.Graphic = Graphic.Load(br);
                }
                GraphicArchive archive;
                switch (zoomFactor)
                {
                case 1:
                case 2:
                case 4:
                    ZoomFactor f = (ZoomFactor)zoomFactor;
                    archive = new GraphicArchive(f);
                    break;

                default:
                    throw new InvalidDataException("Invalid ZoomFactor");
                }
                archive.graphics = graphics;

                return(archive);
            }
        }
예제 #2
0
 public Graphic this[int elementNumber, int animationPhase, int alternative]
 {
     get
     {
         ArchiveElement element = this.graphics.SingleOrDefault(x => x.ElementNumber == elementNumber && x.AnimationPhase == animationPhase && x.Alternative == alternative);
         if (element != null)
         {
             return(element.Graphic);
         }
         return(null);
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            int uid = (int)e.ExtraData;

            Controls.WindowCaption.Captions[Application.Current.MainWindow].ShowBackground = true;
            ThreadPool.QueueUserWorkItem(async delegate
            {
                var response = await BiliClient.Account.GetUserSpaceAsync(uid);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    NameText.Text = response.card.name;
                    SignText.Text = response.card.sign;
                    UidText.Text  = $"Uid:{response.card.mid}";

                    var tabClass = response.tab;

                    {
                        switch (response.card.sex)
                        {
                        case "男": SexText.Text = "\u2642"; SexText.Foreground = new SolidColorBrush(Colors.DodgerBlue); break;

                        case "女": SexText.Text = "\u2640"; SexText.Foreground = new SolidColorBrush(Colors.Lavender); break;

                        default: SexText.Text = "\u2642\u00BF\u003F\u2640"; SexText.Foreground = new SolidColorBrush(Colors.Gray); break;
                        }
                    }

                    {
                        var level      = response.card.level_info;
                        LevelPath.Fill = FindResource($"Level{level.current_level}Color") as SolidColorBrush;
                        LevelPath.Data = FindResource($"Level{level.current_level}Icon") as StreamGeometry;
                        ExpText.Text   = $"{level.current_exp}/{level.next_exp}";
                        if (Regex.Match(level.next_exp, "[0-9](1-5)").Success)
                        {
                            ExpBar.Value = level.current_exp * 1.0d / int.Parse(level.next_exp);
                        }
                        else
                        {
                            ExpBar.ShowError = true;
                        }
                    }

                    {
                        FansText.Text   = response.card.fans.ToString();
                        FollowText.Text = response.card.attention.ToString();
                        LikeText.Text   = response.card.likes.like_num.ToString();
                    }

                    {
                        Vip vipData = response.card.vip;
                        if (vipData.vipStatus == 1)
                        {
                            BigVipElement.Visibility = Visibility.Visible;
                            BigVipText.Text          = vipData.label.text;
                        }
                        else
                        {
                            BigVipElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var live = response.live;
                        LiveRoomElement.Visibility = live.liveStatus == 1 ? Visibility.Visible : Visibility.Collapsed;
                    }

                    {
                        var archive = response.archive;
                        if (tabClass.archive)
                        {
                            ArchiveElement.Init(response.archive, response.card.mid);
                        }
                        else
                        {
                            ArchiveElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var article = response.article;
                        if (tabClass.article)
                        {
                        }
                        else
                        {
                            ArticleElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    {
                        var season = response.season;
                        if (tabClass.bangumi)
                        {
                            SeasonElement.Init(season.item, response.card.mid);
                        }
                        else
                        {
                            SeasonElement.Visibility = Visibility.Collapsed;
                        }
                    }

                    FollowUserButton.SetResourceReference(ContentProperty, "User.FollowUser");
                });

                if (response.images != null)
                {
                    var topPhotoPath = await BiliClient.GetFileAsCacheAsync(response.images.imgUrl);
                    Application.Current.Dispatcher.Invoke(() => TopPhotoComponent.Source = new BitmapImage(new Uri(topPhotoPath, UriKind.RelativeOrAbsolute)));
                }

                var facePath = await BiliClient.GetFileAsCacheAsync(response.card.face);
                Application.Current.Dispatcher.Invoke(() => FaceComponent.Source = new BitmapImage(new Uri(facePath, UriKind.RelativeOrAbsolute)));
            });
        }