private void generatePackButton_Click(object sender, RoutedEventArgs e) { GadgetItemOnline item = this.appListBox.SelectedItem as GadgetItemOnline; if (item == null) { return; } string thumbnail = System.IO.Path.GetDirectoryName(item.DllFile); thumbnail = System.IO.Path.Combine(thumbnail, @"AppLogos\"); if (!Directory.Exists(thumbnail)) { Directory.CreateDirectory(thumbnail); } thumbnail += item.Id; thumbnail += System.IO.Path.GetExtension(item.Thumbnail); CreatePackWindow form = new CreatePackWindow(); form.ShowDialog(); }
private void loadAppItem(string fileName) { GadgetItemOnline item = Helper.LoadApp(fileName); this.gadetItemOnline = item; if (item == null) { MessageBox.Show("加载应用失败,请把打包工具与您的Dll文件放在同一文件夹下!", "打包工具", MessageBoxButton.OK, MessageBoxImage.Error); return; } this.titleTextBlock.Text = item.Title; this.descriptionTextBlock.Text = item.Description; // this.fileNameTextBox.Text = System.IO.Path.GetDirectoryName(item.DllFile); this.thumbnailFile = item.LocalThumbnailFile; this.id = this.gadetItemOnline.Id; string drive = System.IO.Path.GetPathRoot(item.DllFile); Assembly assembly = Assembly.LoadFile(item.DllFile); AssemblyName[] refAssemblies = assembly.GetReferencedAssemblies(); foreach (AssemblyName name in refAssemblies) { Assembly refAssembly = Assembly.Load(name); if (drive == System.IO.Path.GetPathRoot(refAssembly.Location)) { if (refAssembly.ManifestModule.Name == "SoonLearning.AppCenter.exe" || refAssembly.ManifestModule.Name == "SoonLearning.AppCenter.Common.dll") { continue; } this.additionalFileListBox.Items.Add(refAssembly.Location); } } }
private void LoadApp(string fileName) { try { Assembly gadgetAssembly = Assembly.LoadFile(fileName); AssemblyName[] refAssembly = gadgetAssembly.GetReferencedAssemblies(); Module[] modules = gadgetAssembly.GetModules(); foreach (Module module in modules) { Type[] types = module.GetTypes(); foreach (Type type in types) { if (type.IsClass && !type.IsAbstract) { Type entryInterface = type.GetInterface("IGadgetEntry"); Type authorInterface = type.GetInterface("IAuthorInfo"); if (entryInterface != null) { object instance = gadgetAssembly.CreateInstance(type.FullName); GadgetItemOnline item = new GadgetItemOnline(fileName); PropertyInfo piId = entryInterface.GetProperty("Id"); PropertyInfo piTitle = entryInterface.GetProperty("Title"); PropertyInfo piDescription = entryInterface.GetProperty("Description"); PropertyInfo piCreateDate = entryInterface.GetProperty("CreateDate"); PropertyInfo piAppType = entryInterface.GetProperty("Tag"); PropertyInfo piAppSubType = entryInterface.GetProperty("SubTag"); PropertyInfo piThumbnail = entryInterface.GetProperty("Thumbnail"); object id = piId.GetValue(instance, null); object title = piTitle.GetValue(instance, null); object thumbnail = piThumbnail.GetValue(instance, null); string thumbnailFile = ExtractLogo(thumbnail as string, id as string, gadgetAssembly); item.Id = (string)id; item.Title = (string)title; item.Entry = type.FullName; item.Description = (string)piDescription.GetValue(instance, null); item.CreateDate = (DateTime)piCreateDate.GetValue(instance, null); item.AppType = Convert.ToInt32(piAppType.GetValue(instance, null)); item.AppSubType = Convert.ToInt32(piAppSubType.GetValue(instance, null)); item.Thumbnail = @"http://www.soonlearning.com/AppThumbnails/" + System.IO.Path.GetFileName(thumbnailFile); item.PackageUrl = @"http://www.soonlearning.com/AppPackages/" + item.Id + ".zip"; item.Version = gadgetAssembly.GetName().Version.ToString(); if (authorInterface != null) { PropertyInfo piCreator = authorInterface.GetProperty("Name"); PropertyInfo piWebSite = authorInterface.GetProperty("WebSite"); item.Creator = (string)piCreator.GetValue(instance, null); item.CreatorWebSite = (string)piWebSite.GetValue(instance, null); item.CreatorLogo = @"http://www.soonlearning.com/AppPackages/" + item.Creator + ".png"; } int index = this.appListBox.Items.Add(item); } } } } } catch { } }
private bool ExtractPackFile() { try { double price = 0.0f; if (!double.TryParse(this.priceTextBox.Text, out price)) { MessageBox.Show("请为应用输入正确的价格。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } string userId = this.userIdTextBox.Text; string password = this.passwordTextBox.Password; if (string.IsNullOrEmpty(userId)) { MessageBox.Show("请输入注册用的邮箱或者登陆ID。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } if (string.IsNullOrEmpty(password)) { MessageBox.Show("请输入密码。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } FileStream fs = File.OpenRead(this.appFileTextBox.Text); // Check File Header string fileHeader = this.ReadString(fs); if (fileHeader != "{B5F6844E-984C-4129-8D19-79FDEFBDD5DC}" && fileHeader != "{BE4A1507-5B37-42EA-9E08-43EF4F363C42}") { MessageBox.Show("安装包格式不正确。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } // Check AppTitle and AppId string appId = this.ReadString(fs); string appTitle = this.ReadString(fs); this.appItem = new GadgetItemOnline(); appItem.Id = appId; appItem.Title = appTitle; // Description appItem.Description = this.ReadString(fs); // Logos appItem.Thumbnail = this.ExtractLogo(fs, appId); // Entry File; string temp = this.ReadString(fs); temp = this.ReadString(fs); appItem.AppType = BitConverter.ToInt32(this.ReadBytes(fs), 0); appItem.AppSubType = BitConverter.ToInt32(this.ReadBytes(fs), 0); appItem.CreateDate = DateTime.Parse(this.ReadString(fs)); appItem.Creator = this.ReadString(fs); appItem.CreatorLogo = this.ReadString(fs); appItem.CreatorWebSite = this.ReadString(fs); fs.Close(); } catch (Exception ex) { Debug.Assert(false, ex.Message); StringBuilder strBuilder = new StringBuilder("安装包格式错误."); strBuilder.AppendLine(ex.Message); MessageBox.Show(strBuilder.ToString(), "上传应用", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } return(true); }