Ejemplo n.º 1
0
 void OnApplicationPause(bool paused)
 {
     if (!paused && ShareMap.FileWaitingToImport())
     {
         Close(Scenes.FILE_RECEIVE);
     }
 }
Ejemplo n.º 2
0
 void OnApplicationPause(bool paused)
 {
     if (!paused && ShareMap.CatchSharedFile())
     {
         Close("fileReceiveScene");
     }
 }
Ejemplo n.º 3
0
 void OnApplicationPause(bool pauseStatus)
 {
     Debug.unityLogger.Log("EditorFile", "OnApplicationPause(" + pauseStatus + ")");
     if (pauseStatus)
     {
         Save();
     }
     else if (ShareMap.FileWaitingToImport())
     {
         if (importWorldHandler == null)
         {
             Save();
             SceneManager.LoadScene(Scenes.FILE_RECEIVE);
         }
         else
         {
             try
             {
                 importWorldHandler(ShareMap.GetImportStream());
             }
             catch (System.Exception e)
             {
                 DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "An error occurred while reading the file.");
                 Debug.LogError(e);
             }
         }
     }
 }
Ejemplo n.º 4
0
    private IEnumerator LoadWorldCoroutine(string path = null, System.IO.Stream stream = null)
    {
        loadingWorld = true;
        errorMessage = null;
        yield return(null);

        yield return(null);

        try
        {
            if (stream != null)
            {
                dataList = ReadWorldFile.ReadEmbeddedData(stream, type);
            }
            else
            {
                dataList = ReadWorldFile.ReadEmbeddedData(path, type);
            }
        }
        catch (MapReadException e)
        {
            errorMessage = e.Message;
            Debug.LogError(e.InnerException);
        }
        finally
        {
            loadingWorld = false;
            if (stream != null)
            {
                stream.Close();
                ShareMap.ClearFileWaitingToImport();
            }
        }
    }
Ejemplo n.º 5
0
    // callback MUST dispose the stream when done!
    public static void ImportAudioStream(System.Action <Stream> callback)
    {
// TODO: get this to work with Android eventually
// right now it can't open files unless they are in a .nomedia folder (doesn't have read permission)
// and the files it can open have names obscured.
//#if UNITY_ANDROID && !UNITY_EDITOR
#if false
        CheckPermission(NativeGallery.GetAudioFromGallery((path) => {
            if (path == null)
            {
                callback(null);
                return;
            }
            try
            {
                callback(File.Open(path, FileMode.Open));
            }
            catch (System.Exception e)
            {
                DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "Error importing audio file");
                Debug.LogError(e);
            }
        }));
#else
        ShareMap.OpenFileManager();
#endif
    }
Ejemplo n.º 6
0
    private void ImportWorld(string name)
    {
        if (name.Length == 0)
        {
            Destroy(this);
            return;
        }
        string newPath = WorldFiles.GetNewWorldPath(name);

        if (File.Exists(newPath))
        {
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            dialog.yesButtonHandler = DestroyThis;
            return;
        }

        try
        {
            ShareMap.ImportSharedFile(newPath);
            MenuGUI.OpenWorld(newPath, Scenes.EDITOR);
            openingWorld = true;
            Destroy(this);
        }
        catch (System.Exception e)
        {
            Debug.Log(e);
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "Error importing world");
            dialog.yesButtonHandler = DestroyThis;
        }
    }
Ejemplo n.º 7
0
 private void CheckSharedFile()
 {
     if (ShareMap.FileWaitingToImport())
     {
         SceneManager.LoadScene(Scenes.FILE_RECEIVE);
     }
 }
Ejemplo n.º 8
0
 private void CheckSharedFile()
 {
     if (ShareMap.CatchSharedFile())
     {
         SceneManager.LoadScene("fileReceiveScene");
     }
 }
Ejemplo n.º 9
0
    private void ImportMap(string name)
    {
        if (name.Length == 0)
        {
            Close();
            return;
        }
        string newPath = WorldFiles.GetFilePath(name);

        if (File.Exists(newPath))
        {
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            dialog.yesButtonHandler = Close;
            return;
        }

        try
        {
            using (FileStream fileStream = File.Create(newPath))
            {
                ShareMap.ReadSharedURLAndroid(fileStream);
            }
            Close();
        }
        catch (System.Exception e)
        {
            Debug.Log(e);
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "Error importing world");
            dialog.yesButtonHandler = Close;
        }
    }
Ejemplo n.º 10
0
 void OnDestroy()
 {
     ShareMap.ClearFileWaitingToImport();
     if (!openingWorld)
     {
         SceneManager.LoadScene(Scenes.MENU);
     }
 }
Ejemplo n.º 11
0
 void OnApplicationPause(bool pauseStatus)
 {
     Debug.unityLogger.Log("EditorFile", "OnApplicationPause(" + pauseStatus + ")");
     if (pauseStatus)
         Save();
     else if (ShareMap.CatchSharedFile())
     {
         Save();
         SceneManager.LoadScene("fileReceiveScene");
     }
 }
Ejemplo n.º 12
0
    void Start()
    {
        ShareMap.MarkIntentUsedAndroid();

        TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();

        inputDialog.prompt        = "Enter name for imported world...";
        inputDialog.handler       = ImportMap;
        inputDialog.cancelHandler = Close;
        inputDialog.guiSkin       = guiSkin;
    }
Ejemplo n.º 13
0
    private void CreateWorldOverflowMenu(string path)
    {
        string name = Path.GetFileNameWithoutExtension(path);

        worldOverflowMenu       = gameObject.AddComponent <OverflowMenuGUI>();
        selectedWorldPath       = path;
        worldOverflowMenu.items = new OverflowMenuGUI.MenuItem[]
        {
            new OverflowMenuGUI.MenuItem("Play", GUIIconSet.instance.play, () => {
                MenuGUI.OpenWorld(path, Scenes.GAME);
            }),
            new OverflowMenuGUI.MenuItem("Rename", GUIIconSet.instance.rename, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new name for " + name;
                inputDialog.handler            = RenameWorld;
            }),
            new OverflowMenuGUI.MenuItem("Copy", GUIIconSet.instance.copy, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new world name...";
                inputDialog.handler            = CopyWorld;
            }),
            new OverflowMenuGUI.MenuItem("Delete", GUIIconSet.instance.delete, () => {
                DialogGUI dialog        = gameObject.AddComponent <DialogGUI>();
                dialog.message          = "Are you sure you want to delete " + name + "?";
                dialog.yesButtonText    = "Yes";
                dialog.noButtonText     = "No";
                dialog.yesButtonHandler = () =>
                {
                    File.Delete(path);
                    UpdateWorldList();
                };
            }),
#if (UNITY_ANDROID || UNITY_IOS)
            new OverflowMenuGUI.MenuItem("Share", GUIIconSet.instance.share,
                                         () => ShareMap.Share(path))
#endif
        };
    }
Ejemplo n.º 14
0
    private void CreateWorldOverflowMenu(string fileName)
    {
        worldOverflowMenu       = gameObject.AddComponent <OverflowMenuGUI>();
        selectedWorld           = fileName;
        worldOverflowMenu.items = new OverflowMenuGUI.MenuItem[]
        {
            new OverflowMenuGUI.MenuItem("Play", GUIIconSet.instance.play, () => {
                MenuGUI.OpenMap(fileName, "playScene");
            }),
            new OverflowMenuGUI.MenuItem("Rename", GUIIconSet.instance.rename, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new name for " + fileName;
                inputDialog.handler            = RenameMap;
            }),
            new OverflowMenuGUI.MenuItem("Copy", GUIIconSet.instance.copy, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new world name...";
                inputDialog.handler            = CopyMap;
            }),
            new OverflowMenuGUI.MenuItem("Delete", GUIIconSet.instance.delete, () => {
                DialogGUI dialog        = gameObject.AddComponent <DialogGUI>();
                dialog.message          = "Are you sure you want to delete " + fileName + "?";
                dialog.yesButtonText    = "Yes";
                dialog.noButtonText     = "No";
                dialog.yesButtonHandler = () =>
                {
                    File.Delete(WorldFiles.GetFilePath(fileName));
                    UpdateMapList();
                };
            }),
#if UNITY_ANDROID
            new OverflowMenuGUI.MenuItem("Share", GUIIconSet.instance.share, () => {
                string path = WorldFiles.GetFilePath(fileName);
                ShareMap.ShareAndroid(path);
            })
#endif
        };
    }
Ejemplo n.º 15
0
    public override void WindowGUI()
    {
        if (loadingWorld)
        {
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Loading world...");
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
        }
        else if (!worldSelected)
        {
            scroll = GUILayout.BeginScrollView(scroll);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Choose a file to open in N-Space", GUIStyleSet.instance.buttonLarge))
            {
                ShareMap.OpenFileManager();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Label("Or import from a world...");
            for (int i = 0; i < worldPaths.Count; i++)
            {
                string path = worldPaths[i];
                string name = worldNames[i];

                if (GUILayout.Button(name, GUIStyleSet.instance.buttonLarge))
                {
                    worldSelected = true;
                    StartCoroutine(LoadWorldCoroutine(path));
                    scroll         = Vector2.zero;
                    scrollVelocity = Vector2.zero;
                }
            }
            GUILayout.EndScrollView();
        }
        else // world is selected
        {
            if (GUIUtils.HighlightedButton("Back to world list", GUIStyleSet.instance.buttonLarge))
            {
                worldSelected  = false;
                dataList       = null;
                scroll         = Vector2.zero;
                scrollVelocity = Vector2.zero;
                StopPlayer();
            }
            if (dataList != null && dataList.Count > 0)
            {
                foreach (EmbeddedData data in dataList)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button(data.name, GUIStyleSet.instance.buttonLarge))
                    {
                        dataAction(data);
                        Destroy(this);
                    }
                    if (playerFactory != null && GUIUtils.HighlightedButton(
                            GUIIconSet.instance.playAudio,
                            GUIStyleSet.instance.buttonLarge,
                            playingData == data,
                            GUILayout.ExpandWidth(false)))
                    {
                        if (StopPlayer() != data)
                        {
                            playingAudio = playerFactory(data.bytes);
                            playingData  = data;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (errorMessage != null)
                {
                    ActionBarGUI.ActionBarLabel(errorMessage);
                }
                else
                {
                    ActionBarGUI.ActionBarLabel("World contains no " + type.ToString() + " files.");
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
        }
    }
Ejemplo n.º 16
0
        public async Task <IActionResult> EnableElementSharing(int userId, [FromQuery] string elementId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            try
            {
                if (!await fsc.AccessControl.CheckPermissionsWithUsernameAsync(elementId, userId.ToString(), true, false, false, false))
                {
                    return(Unauthorized());
                }
                var shareId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                shareId = shareId.Replace("/", "t");
                var fileInfo = await fsc.AccessControl.AuthorizeTokenAsync(elementId, shareId, true, true, true);

                if (fileInfo.Type == 2)
                {
                    var subElems = await fsc.Directories.GetSubelementsAsync(fileInfo.ID);

                    foreach (var item in subElems)
                    {
                        if (item.Type == 2)
                        {
                            continue;
                        }

                        var itemInfo = await fsc.AccessControl.AuthorizeTokenAsync(item.ID, shareId, true, true, true);

                        await fsc.Files.SetCustomMetadataAsync(item.ID, "ShareID", String.Empty);

                        await fsc.Files.SetCustomMetadataAsync(item.ID, "Shared", false);
                    }
                }

                ShareMap f = new ShareMap()
                {
                    ElementId = fileInfo.ID,
                    Type      = fileInfo.Type,
                    ShareId   = shareId,
                    Active    = true
                };

                filesService.Add <ShareMap>(f);

                await fsc.Files.SetCustomMetadataAsync(elementId, "ShareID", shareId);

                await fsc.Files.SetCustomMetadataAsync(elementId, "Shared", true);

                if (await filesService.SaveAll())
                {
                    return(Ok(shareId));
                }

                return(BadRequest("Failed to share element"));
            }
            catch (MDBFS.Exceptions.MdbfsElementNotFoundException)
            {
                return(NotFound("Unknown element id"));
            }
            catch (Exception)
            {
                return(BadRequest("Failed to share element"));
            }
        }