public void LoadData() { label1.Content = SelectedPath; string userPath = null; string path = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Packages"; DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] dics = root.GetDirectories(); foreach (DirectoryInfo di in dics) { if (di.Name.StartsWith("Microsoft.Windows.ContentDeliveryManager_")) { userPath = di.FullName + @"\LocalState\TargetedContentCache"; break; } } DirectoryInfo userDi = new DirectoryInfo(userPath); DirectoryInfo[] userDis = userDi.GetDirectories(); foreach (DirectoryInfo di in userDis) { DirectoryInfo[] ds = di.GetDirectories(); foreach (DirectoryInfo d in ds) { FileInfo[] files = d.GetFiles(); foreach (FileInfo file in files) { string text = File.ReadAllText(file.FullName); JavaScriptSerializer js = new JavaScriptSerializer(); //实例化一个能够序列化数据的类 Info info = js.Deserialize <Info>(text); //将json数据转化为对象类型并赋值给list if (info.Name == "LockScreen") { InfoProperties infoProperties = info.Properties; IpList.Add(infoProperties); #if DEBUG string mydir = System.Environment.CurrentDirectory; int pos = mydir.LastIndexOf("MyCShapeWPF"); string baseMydir = mydir.Substring(0, pos); string imageDir = baseMydir + @"images\"; string jsonDir = baseMydir + @"json\"; File.WriteAllText(jsonDir + file.Name + ".json", text); LandscapeImage li = infoProperties.LandscapeImage; string liPath = li.Image; File.WriteAllBytes(imageDir + liPath.Substring(liPath.LastIndexOf('\\') + 1) + ".jpg", File.ReadAllBytes(liPath)); PortraitImage pi = infoProperties.PortraitImage; string piPath = pi.Image; File.WriteAllBytes(imageDir + piPath.Substring(piPath.LastIndexOf('\\') + 1) + ".jpg", File.ReadAllBytes(piPath)); #endif } } } } }
public void ShowNextImages() { if (CurrentPos >= IpList.Count || CurrentPos < 0) { return; } InfoProperties ip = IpList.ToArray()[CurrentPos] as InfoProperties; BitmapImage bi1 = new BitmapImage(new Uri(ip.LandscapeImage.Image)); image1.Source = bi1; BitmapImage bi2 = new BitmapImage(new Uri(ip.PortraitImage.Image)); image2.Source = bi2; CurrentPos++; }