public static IEnumerable <string> GetEntryTypeExtensions(ExternalContentType type) { switch (type) { case ExternalContentType.World: yield return(".scworld"); break; case ExternalContentType.BlocksTexture: yield return(".scbtex"); yield return(".png"); break; case ExternalContentType.CharacterSkin: yield return(".scskin"); break; case ExternalContentType.FurniturePack: yield return(".scfpack"); break; } }
private static string GetFilterDisplayName(ExternalContentType filter) { if (filter == ExternalContentType.Unknown) { return(LanguageControl.Get(fName, 8)); } return(ExternalContentManager.GetEntryTypeDescription(filter)); }
public static void VerifyLinkContent(string address, string name, ExternalContentType type, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure) { progress = (progress ?? new CancellableProgress()); WebManager.Get(address, null, null, progress, delegate(byte[] data) { ExternalContentManager.ImportExternalContent(new MemoryStream(data), type, "__Temp", delegate(string downloadedName) { ExternalContentManager.DeleteExternalContent(type, downloadedName); success(data); }, failure); }, failure); }
public static void ImportExternalContent(Stream stream, ExternalContentType type, string name, Action <string> success, Action <Exception> failure) { Task.Run(delegate { try { success(ImportExternalContentSync(stream, type, name)); } catch (Exception obj) { failure(obj); } }); }
public SelectExternalContentTypeDialog(string title, Action <ExternalContentType> selectionHandler) : base(title, from v in EnumUtils.GetEnumValues(typeof(ExternalContentType)) where ExternalContentManager.IsEntryTypeDownloadSupported((ExternalContentType) v) select v, 64f, delegate(object item) { ExternalContentType type = (ExternalContentType)item; XElement node = ContentManager.Get <XElement>("Widgets/SelectExternalContentTypeItem"); ContainerWidget obj = (ContainerWidget)Widget.LoadWidget(null, node, null); obj.Children.Find <RectangleWidget>("SelectExternalContentType.Icon").Subtexture = ExternalContentManager.GetEntryTypeIcon(type); obj.Children.Find <LabelWidget>("SelectExternalContentType.Text").Text = ExternalContentManager.GetEntryTypeDescription(type); return(obj); }, delegate(object item) { selectionHandler((ExternalContentType)item); }) { }
public static bool DoesEntryTypeRequireName(ExternalContentType type) { switch (type) { case ExternalContentType.BlocksTexture: return(true); case ExternalContentType.CharacterSkin: return(true); case ExternalContentType.FurniturePack: return(true); default: return(false); } }
public static void Download(string address, string name, ExternalContentType type, string userId, CancellableProgress progress, Action success, Action <Exception> failure) { progress = (progress ?? new CancellableProgress()); if (!WebManager.IsInternetConnectionAvailable()) { failure(new InvalidOperationException("Internet connection is unavailable.")); } else { WebManager.Get(address, null, null, progress, delegate(byte[] data) { string hash = CalculateContentHashString(data); ExternalContentManager.ImportExternalContent(new MemoryStream(data), type, name, delegate(string downloadedName) { m_idToAddressMap[MakeContentIdString(type, downloadedName)] = address; Feedback(address, "Success", null, hash, data.Length, userId, progress, delegate { }, delegate { }); AnalyticsManager.LogEvent("[CommunityContentManager] Download Success", new AnalyticsParameter("Name", name)); success(); }, delegate(Exception error) { Feedback(address, "ImportFailure", null, hash, data.Length, userId, null, delegate { }, delegate { }); AnalyticsManager.LogEvent("[CommunityContentManager] Import Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Error", error.Message.ToString())); failure(error); }); }, delegate(Exception error) { Feedback(address, "DownloadFailure", null, null, 0L, userId, null, delegate { }, delegate { }); AnalyticsManager.LogEvent("[CommunityContentManager] Download Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Error", error.Message.ToString())); failure(error); }); } }
public override void Update() { ListItem selectedItem = (ListItem)m_contentList.SelectedItem; m_deleteButton.IsEnabled = (selectedItem != null && !selectedItem.IsBuiltIn); m_uploadButton.IsEnabled = (selectedItem != null && !selectedItem.IsBuiltIn); m_filterLabel.Text = GetFilterDisplayName(m_filter); if (m_deleteButton.IsClicked) { string smallMessage = (selectedItem.UseCount <= 0) ? string.Format(LanguageControl.Get(fName, 5), selectedItem.DisplayName) : string.Format(LanguageControl.Get(fName, 6), selectedItem.DisplayName, selectedItem.UseCount); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 9), smallMessage, LanguageControl.Get("Usual", "yes"), LanguageControl.Get("Usual", "no"), delegate(MessageDialogButton button) { if (button == MessageDialogButton.Button1) { ExternalContentManager.DeleteExternalContent(selectedItem.Type, selectedItem.Name); UpdateList(); } })); } if (m_uploadButton.IsClicked) { ExternalContentManager.ShowUploadUi(selectedItem.Type, selectedItem.Name); } if (m_changeFilterButton.IsClicked) { List <ExternalContentType> list = new List <ExternalContentType>(); list.Add(ExternalContentType.Unknown); list.Add(ExternalContentType.BlocksTexture); list.Add(ExternalContentType.CharacterSkin); list.Add(ExternalContentType.FurniturePack); DialogsManager.ShowDialog(null, new ListSelectionDialog(LanguageControl.Get(fName, 7), list, 60f, (object item) => GetFilterDisplayName((ExternalContentType)item), delegate(object item) { if ((ExternalContentType)item != m_filter) { m_filter = (ExternalContentType)item; UpdateList(); } })); } if (base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked) { ScreensManager.SwitchScreen(ScreensManager.PreviousScreen); } }
public static bool IsEntryTypeDownloadSupported(ExternalContentType type) { switch (type) { case ExternalContentType.World: return(true); case ExternalContentType.BlocksTexture: return(true); case ExternalContentType.CharacterSkin: return(true); case ExternalContentType.FurniturePack: return(true); default: return(false); } }
public static string ImportExternalContentSync(Stream stream, ExternalContentType type, string name) { switch (type) { case ExternalContentType.World: return(WorldsManager.ImportWorld(stream)); case ExternalContentType.BlocksTexture: return(BlocksTexturesManager.ImportBlocksTexture(name, stream)); case ExternalContentType.CharacterSkin: return(CharacterSkinsManager.ImportCharacterSkin(name, stream)); case ExternalContentType.FurniturePack: return(FurniturePacksManager.ImportFurniturePack(name, stream)); default: throw new InvalidOperationException(LanguageControl.Get(fName, 4)); } }
public static void UnpackWorld(string directoryName, Stream sourceStream, bool importEmbeddedExternalContent) { if (!Storage.DirectoryExists(directoryName)) { throw new InvalidOperationException($"Cannot import world into \"{directoryName}\" because this directory does not exist."); } using (ZipArchive zipArchive = ZipArchive.Open(sourceStream, keepStreamOpen: true)) { foreach (ZipArchiveEntry item in zipArchive.ReadCentralDir()) { string text = item.FilenameInZip.Replace('\\', '/'); string extension = Storage.GetExtension(text); if (text.StartsWith("EmbeddedContent")) { try { if (importEmbeddedExternalContent) { MemoryStream memoryStream = new MemoryStream(); zipArchive.ExtractFile(item, memoryStream); memoryStream.Position = 0L; ExternalContentType type = ExternalContentManager.ExtensionToType(extension); ExternalContentManager.ImportExternalContentSync(memoryStream, type, Storage.GetFileNameWithoutExtension(text)); } } catch (Exception ex) { Log.Warning($"Failed to import embedded content \"{text}\". Reason: {ex.Message}"); } } else { using (Stream stream = Storage.OpenFile(Storage.CombinePaths(directoryName, Storage.GetFileName(text)), OpenFileMode.Create)) { zipArchive.ExtractFile(item, stream); } } } } }
public static Subtexture GetEntryTypeIcon(ExternalContentType type) { switch (type) { case ExternalContentType.Directory: return(ContentManager.Get <Subtexture>("Textures/Atlas/FolderIcon")); case ExternalContentType.World: return(ContentManager.Get <Subtexture>("Textures/Atlas/WorldIcon")); case ExternalContentType.BlocksTexture: return(ContentManager.Get <Subtexture>("Textures/Atlas/TexturePackIcon")); case ExternalContentType.CharacterSkin: return(ContentManager.Get <Subtexture>("Textures/Atlas/CharacterSkinIcon")); case ExternalContentType.FurniturePack: return(ContentManager.Get <Subtexture>("Textures/Atlas/FurnitureIcon")); default: return(ContentManager.Get <Subtexture>("Textures/Atlas/QuestionMarkIcon")); } }
public static string GetEntryTypeDescription(ExternalContentType type) { switch (type) { case ExternalContentType.Directory: return(LanguageControl.Get(fName, "Directory")); case ExternalContentType.World: return(LanguageControl.Get(fName, "World")); case ExternalContentType.BlocksTexture: return(LanguageControl.Get(fName, "Blocks Texture")); case ExternalContentType.CharacterSkin: return(LanguageControl.Get(fName, "Character Skin")); case ExternalContentType.FurniturePack: return(LanguageControl.Get(fName, "Furniture Pack")); default: return(string.Empty); } }
public override void Update() { string text = m_linkTextBoxWidget.Text.Trim(); string text2 = m_nameTextBoxWidget.Text.Trim(); m_typeLabelWidget.Text = ExternalContentManager.GetEntryTypeDescription(m_type); m_typeIconWidget.Subtexture = ExternalContentManager.GetEntryTypeIcon(m_type); m_publishButtonWidget.IsEnabled = (text.Length > 0 && text2.Length > 0); if (m_changeTypeButtonWidget.IsClicked) { DialogsManager.ShowDialog(base.ParentWidget, new SelectExternalContentTypeDialog("Select Content Type", delegate(ExternalContentType item) { m_type = item; })); } else if (base.Input.Cancel || m_cancelButtonWidget.IsClicked) { DialogsManager.HideDialog(this); } else if (m_publishButtonWidget.IsClicked) { CancellableBusyDialog busyDialog = new CancellableBusyDialog("Publishing", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); CommunityContentManager.Publish(text, text2, m_type, m_user, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Link Published Successfully", "It should start appearing in the listings after it is moderated. Please keep the file accessible through this link, so that other community members can download it.", LanguageControl.Get("Usual", "ok"), null, delegate { DialogsManager.HideDialog(this); })); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } }
public static void DeleteExternalContent(ExternalContentType type, string name) { switch (type) { case ExternalContentType.World: WorldsManager.DeleteWorld(name); break; case ExternalContentType.BlocksTexture: BlocksTexturesManager.DeleteBlocksTexture(name); break; case ExternalContentType.CharacterSkin: CharacterSkinsManager.DeleteCharacterSkin(name); break; case ExternalContentType.FurniturePack: FurniturePacksManager.DeleteFurniturePack(name); break; default: throw new InvalidOperationException(LanguageControl.Get(fName, 4)); } }
public override void Update() { string text = m_linkTextBoxWidget.Text.Trim(); string name = m_nameTextBoxWidget.Text.Trim(); m_typeLabelWidget.Text = ExternalContentManager.GetEntryTypeDescription(m_type); m_typeIconWidget.Subtexture = ExternalContentManager.GetEntryTypeIcon(m_type); if (ExternalContentManager.DoesEntryTypeRequireName(m_type)) { m_nameTextBoxWidget.IsEnabled = true; m_downloadButtonWidget.IsEnabled = (text.Length > 0 && name.Length > 0 && m_type != ExternalContentType.Unknown); if (m_updateContentName) { m_nameTextBoxWidget.Text = GetNameFromLink(m_linkTextBoxWidget.Text); m_updateContentName = false; } } else { m_nameTextBoxWidget.IsEnabled = false; m_nameTextBoxWidget.Text = string.Empty; m_downloadButtonWidget.IsEnabled = (text.Length > 0 && m_type != ExternalContentType.Unknown); } if (m_updateContentType) { m_type = GetTypeFromLink(m_linkTextBoxWidget.Text); m_updateContentType = false; } if (m_changeTypeButtonWidget.IsClicked) { DialogsManager.ShowDialog(base.ParentWidget, new SelectExternalContentTypeDialog("Select Content Type", delegate(ExternalContentType item) { m_type = item; m_updateContentName = true; })); } else if (base.Input.Cancel || m_cancelButtonWidget.IsClicked) { DialogsManager.HideDialog(this); } else if (m_downloadButtonWidget.IsClicked) { CancellableBusyDialog busyDialog = new CancellableBusyDialog("Downloading", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); WebManager.Get(text, null, null, busyDialog.Progress, delegate(byte[] data) { ExternalContentManager.ImportExternalContent(new MemoryStream(data), m_type, name, delegate { DialogsManager.HideDialog(busyDialog); DialogsManager.HideDialog(this); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } }
public static void ShowUploadUi(ExternalContentType type, string name) { DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog(LanguageControl.Get(fName, 9), listingSupportRequired : false, delegate(IExternalContentProvider provider) { try { if (provider != null) { ShowLoginUiIfNeeded(provider, showWarningDialog: true, delegate { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 10), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); Task.Run(delegate { bool needsDelete = false; string sourcePath = null; Stream stream = null; Action cleanup = delegate { Utilities.Dispose(ref stream); if (needsDelete && sourcePath != null) { try { Storage.DeleteFile(sourcePath); } catch { } } }; try { string path; if (type == ExternalContentType.BlocksTexture) { sourcePath = BlocksTexturesManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else if (type == ExternalContentType.CharacterSkin) { sourcePath = CharacterSkinsManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else if (type == ExternalContentType.FurniturePack) { sourcePath = FurniturePacksManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else { if (type != ExternalContentType.World) { throw new InvalidOperationException(LanguageControl.Get(fName, 12)); } busyDialog.LargeMessage = LanguageControl.Get(fName, 13); sourcePath = "android:SurvivalCraft2.2/WorldUpload.tmp"; needsDelete = true; string name2 = WorldsManager.GetWorldInfo(name).WorldSettings.Name; path = $"{name2}.scworld"; using (Stream targetStream = Storage.OpenFile(sourcePath, OpenFileMode.Create)) { WorldsManager.ExportWorld(name, targetStream); } } busyDialog.LargeMessage = LanguageControl.Get(fName, 14); stream = Storage.OpenFile(sourcePath, OpenFileMode.Read); provider.Upload(path, stream, busyDialog.Progress, delegate(string link) { long length = stream.Length; cleanup(); DialogsManager.HideDialog(busyDialog); if (string.IsNullOrEmpty(link)) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "success"), string.Format(LanguageControl.Get(fName, 15), DataSizeFormatter.Format(length)), LanguageControl.Get("Usual", "ok"), null, null)); } else { DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link)); } }, delegate(Exception error) { cleanup(); DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } catch (Exception ex2) { cleanup(); DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex2.Message, LanguageControl.Get("Usual", "ok"), null, null)); } }); }); } } catch (Exception ex) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex.Message, LanguageControl.Get("Usual", "ok"), null, null)); } })); }
public static string GetDownloadedContentAddress(ExternalContentType type, string name) { m_idToAddressMap.TryGetValue(MakeContentIdString(type, name), out string value); return(value); }
public static string MakeContentIdString(ExternalContentType type, string name) { return(type.ToString() + ":" + name); }
public static void Publish(string address, string name, ExternalContentType type, string userId, CancellableProgress progress, Action success, Action <Exception> failure) { progress = (progress ?? new CancellableProgress()); if (MarketplaceManager.IsTrialMode) { failure(new InvalidOperationException("Cannot publish links in trial mode.")); } else if (!WebManager.IsInternetConnectionAvailable()) { failure(new InvalidOperationException("Internet connection is unavailable.")); } else { VerifyLinkContent(address, name, type, progress, delegate(byte[] data) { string value = CalculateContentHashString(data); WebManager.Post(m_scResDirAddress, null, null, WebManager.UrlParametersToStream(new Dictionary <string, string> { { "Action", "publish" }, { "UserId", userId }, { "Name", name }, { "Url", address }, { "Type", type.ToString() }, { "Hash", value }, { "Size", data.Length.ToString(CultureInfo.InvariantCulture) }, { "Platform", VersionsManager.Platform.ToString() }, { "Version", VersionsManager.Version } }), progress, delegate { success(); AnalyticsManager.LogEvent("[CommunityContentManager] Publish Success", new AnalyticsParameter("Name", name), new AnalyticsParameter("Type", type.ToString()), new AnalyticsParameter("Size", data.Length.ToString()), new AnalyticsParameter("User", userId)); }, delegate(Exception error) { failure(error); AnalyticsManager.LogEvent("[CommunityContentManager] Publish Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Type", type.ToString()), new AnalyticsParameter("Size", data.Length.ToString()), new AnalyticsParameter("User", userId), new AnalyticsParameter("Error", error.Message.ToString())); }); }, failure); } }