void TestCloud()
        {
            ICloud cloud = null;
            RemoteStoragePlatform remoteStorrage = RemoteStoragePlatform.All;

            cloud.CloudFileShareResult   += (CloudFileShareResult x, bool y) => { };
            cloud.CloudDownloadUGCResult += (CloudDownloadUGCResult x, bool y) => { };
            b = cloud.Write(s, ba);
            i = cloud.Read(s, ba);
            b = cloud.Forget(s);
            b = cloud.Delete(s);
            cloud.Share(s);
            b = cloud.SetSyncPlatforms(s, remoteStorrage);
            b = cloud.Exists(s);
            b = cloud.Persisted(s);
            i = cloud.GetSize(s);
            l = cloud.Timestamp(s);
            remoteStorrage = cloud.GetSyncPlatforms(s);
            i = cloud.GetFileCount();
            s = cloud.GetFileNameAndSize(i, out i);
            b = cloud.GetQuota(out i, out i);
            b = cloud.IsEnabledForAccount();
            b = cloud.IsEnabledForApplication();
            cloud.SetEnabledForApplication(b);
            cloud.UGCDownload(ugcHandle);
            b         = cloud.GetUGCDetails(ugcHandle, out appID, out s, out i, out steamID);
            i         = cloud.UGCRead(ugcHandle, ba);
            i         = cloud.GetCachedUGCCount();
            ugcHandle = cloud.GetUGCHandle(i);
        }
Beispiel #2
0
        public CloudViewModel(
            CloudState state,
            CreateFolderViewModelFactory createFolderFactory,
            RenameFileViewModelFactory renameFactory,
            FileViewModelFactory fileFactory,
            FolderViewModelFactory folderFactory,
            IAuthViewModel auth,
            IFileManager files,
            ICloud cloud)
        {
            _cloud = cloud;
            Folder = createFolderFactory(this);
            Rename = renameFactory(this);
            Auth   = auth;

            var canInteract = this
                              .WhenAnyValue(
                x => x.Folder.IsVisible,
                x => x.Rename.IsVisible,
                (folder, rename) => !folder && !rename);

            _canInteract = canInteract
                           .ToProperty(this, x => x.CanInteract);

            var canRefresh = this
                             .WhenAnyValue(
                x => x.Folder.IsVisible,
                x => x.Rename.IsVisible,
                x => x.Auth.IsAuthenticated,
                (folder, rename, authenticated) => !folder && !rename && authenticated);

            Refresh = ReactiveCommand.CreateFromTask(
                () => cloud.GetFiles(CurrentPath),
                canRefresh);

            _files = Refresh
                     .Select(
                items => items
                .Select(file => fileFactory(file, this))
                .OrderByDescending(file => file.IsFolder)
                .ThenBy(file => file.Name)
                .ToList())
                     .Where(items => Files == null || !items.SequenceEqual(Files))
                     .ToProperty(this, x => x.Files);

            _isLoading = Refresh
                         .IsExecuting
                         .ToProperty(this, x => x.IsLoading);

            _isReady = Refresh
                       .IsExecuting
                       .Skip(1)
                       .Select(executing => !executing)
                       .ToProperty(this, x => x.IsReady);

            var canOpenCurrentPath = this
                                     .WhenAnyValue(x => x.SelectedFile)
                                     .Select(file => file != null && file.IsFolder)
                                     .CombineLatest(Refresh.IsExecuting, canInteract, (folder, busy, ci) => folder && ci && !busy);

            Open = ReactiveCommand.Create(
                () => Path.Combine(CurrentPath, SelectedFile.Name),
                canOpenCurrentPath);

            var canCurrentPathGoBack = this
                                       .WhenAnyValue(x => x.CurrentPath)
                                       .Where(path => path != null)
                                       .Select(path => path.Length > cloud.InitialPath.Length)
                                       .CombineLatest(Refresh.IsExecuting, canInteract, (valid, busy, ci) => valid && ci && !busy);

            Back = ReactiveCommand.Create(
                () => Path.GetDirectoryName(CurrentPath),
                canCurrentPathGoBack);

            SetPath = ReactiveCommand.Create <string, string>(path => path);

            _currentPath = Open
                           .Merge(Back)
                           .Merge(SetPath)
                           .Select(path => path ?? cloud.InitialPath)
                           .DistinctUntilChanged()
                           .Log(this, $"Current path changed in {cloud.Name}")
                           .ToProperty(this, x => x.CurrentPath, state.CurrentPath ?? cloud.InitialPath);

            var getBreadCrumbs = ReactiveCommand.CreateFromTask(
                () => cloud.GetBreadCrumbs(CurrentPath));

            _breadCrumbs = getBreadCrumbs
                           .Where(items => items != null && items.Any())
                           .Select(items => items.Select(folder => folderFactory(folder, this)))
                           .ToProperty(this, x => x.BreadCrumbs);

            _showBreadCrumbs = getBreadCrumbs
                               .ThrownExceptions
                               .Select(exception => false)
                               .Merge(getBreadCrumbs.Select(items => items != null && items.Any()))
                               .ObserveOn(RxApp.MainThreadScheduler)
                               .ToProperty(this, x => x.ShowBreadCrumbs);

            _hideBreadCrumbs = this
                               .WhenAnyValue(x => x.ShowBreadCrumbs)
                               .Select(show => !show)
                               .ToProperty(this, x => x.HideBreadCrumbs);

            this.WhenAnyValue(x => x.CurrentPath, x => x.IsReady)
            .Where(x => x.Item1 != null && x.Item2)
            .Select(_ => Unit.Default)
            .InvokeCommand(getBreadCrumbs);

            this.WhenAnyValue(x => x.CurrentPath)
            .Skip(1)
            .Select(_ => Unit.Default)
            .InvokeCommand(Refresh);

            this.WhenAnyValue(x => x.CurrentPath)
            .Subscribe(_ => SelectedFile = null);

            _isCurrentPathEmpty = this
                                  .WhenAnyValue(x => x.Files)
                                  .Skip(1)
                                  .Where(items => items != null)
                                  .Select(items => !items.Any())
                                  .ToProperty(this, x => x.IsCurrentPathEmpty);

            _hasErrorMessage = Refresh
                               .ThrownExceptions
                               .Select(exception => true)
                               .ObserveOn(RxApp.MainThreadScheduler)
                               .Merge(Refresh.Select(x => false))
                               .ToProperty(this, x => x.HasErrorMessage);

            var canUploadToCurrentPath = this
                                         .WhenAnyValue(x => x.CurrentPath)
                                         .Select(path => path != null)
                                         .CombineLatest(Refresh.IsExecuting, canInteract, (up, loading, can) => up && can && !loading);

            UploadToCurrentPath = ReactiveCommand.CreateFromObservable(
                () => Observable
                .FromAsync(files.OpenRead)
                .Where(response => response.Name != null && response.Stream != null)
                .Select(args => _cloud.UploadFile(CurrentPath, args.Stream, args.Name))
                .SelectMany(task => task.ToObservable()),
                canUploadToCurrentPath);

            UploadToCurrentPath.InvokeCommand(Refresh);

            var canDownloadSelectedFile = this
                                          .WhenAnyValue(x => x.SelectedFile)
                                          .Select(file => file != null && !file.IsFolder)
                                          .CombineLatest(Refresh.IsExecuting, canInteract, (down, loading, can) => down && !loading && can);

            DownloadSelectedFile = ReactiveCommand.CreateFromObservable(
                () => Observable
                .FromAsync(() => files.OpenWrite(SelectedFile.Name))
                .Where(stream => stream != null)
                .Select(stream => _cloud.DownloadFile(SelectedFile.Path, stream))
                .SelectMany(task => task.ToObservable()),
                canDownloadSelectedFile);

            var canLogout = cloud
                            .IsAuthorized
                            .DistinctUntilChanged()
                            .Select(loggedIn => loggedIn && (
                                        cloud.SupportsDirectAuth ||
                                        cloud.SupportsOAuth ||
                                        cloud.SupportsHostAuth))
                            .CombineLatest(canInteract, (logout, interact) => logout && interact)
                            .ObserveOn(RxApp.MainThreadScheduler);

            Logout = ReactiveCommand.CreateFromTask(cloud.Logout, canLogout);

            _canLogout = canLogout
                         .ToProperty(this, x => x.CanLogout);

            var canDeleteSelection = this
                                     .WhenAnyValue(x => x.SelectedFile)
                                     .Select(file => file != null && !file.IsFolder)
                                     .CombineLatest(Refresh.IsExecuting, canInteract, (del, loading, ci) => del && !loading && ci);

            DeleteSelectedFile = ReactiveCommand.CreateFromTask(
                () => cloud.Delete(SelectedFile.Path, SelectedFile.IsFolder),
                canDeleteSelection);

            DeleteSelectedFile.InvokeCommand(Refresh);

            var canUnselectFile = this
                                  .WhenAnyValue(x => x.SelectedFile)
                                  .Select(selection => selection != null)
                                  .CombineLatest(Refresh.IsExecuting, canInteract, (sel, loading, ci) => sel && !loading && ci);

            UnselectFile = ReactiveCommand.Create(
                () => { SelectedFile = null; },
                canUnselectFile);

            UploadToCurrentPath.ThrownExceptions
            .Merge(DeleteSelectedFile.ThrownExceptions)
            .Merge(DownloadSelectedFile.ThrownExceptions)
            .Merge(Refresh.ThrownExceptions)
            .Merge(getBreadCrumbs.ThrownExceptions)
            .Log(this, $"Exception occured in provider {cloud.Name}")
            .Subscribe();

            this.WhenAnyValue(x => x.CurrentPath)
            .Subscribe(path => state.CurrentPath = path);

            this.WhenAnyValue(x => x.Auth.IsAuthenticated)
            .Select(authenticated => authenticated ? _cloud.Parameters?.Token : null)
            .Subscribe(token => state.Token = token);

            this.WhenAnyValue(x => x.Auth.IsAuthenticated)
            .Select(authenticated => authenticated ? _cloud.Parameters?.User : null)
            .Subscribe(user => state.User = user);

            this.WhenActivated(ActivateAutoRefresh);
        }
Beispiel #3
0
    private void OnGUI()
    {
        GUILayout.Label(status);
        GUILayout.Label(achievementStatus);
        GUILayout.Label(hasLicense.ToString());
        GUILayout.Label(SteamInterface.AppID.ToString());

        if (GUILayout.Button("Unlock Achivement!"))
        {
            if (SteamInterface.Stats.SetAchievement("Your-Achievement-Name"))
            {
                achievementStatus = "Achievement Status: Successfully got an achievement!";
            }
        }

        if (GUILayout.Button("Clear Achivement!"))
        {
            if (SteamInterface.Stats.ClearAchievement("Your-Achievement-Name"))
            {
                achievementStatus = "Achievement Status: Successfully cleared an achievement!";
            }
        }

        if (GUILayout.Button("Get Achievement!"))
        {
            StatsGetAchievementResult result = SteamInterface.Stats.GetAchievement("Your-Achievement-Name");
            if (result.result)
            {
                if (result.sender)
                {
                    achievementStatus = "Achievement Status: achievement is unlocked!";
                }
                else
                {
                    achievementStatus = "Achievement Status: achievement is locked!";
                }
            }
        }

        GUILayout.Space(24);

        if (GUILayout.Button("Write File"))
        {
            byte[]   buffer       = System.Text.Encoding.ASCII.GetBytes("Hello World again!!!");
            GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            try
            {
                System.IntPtr bufferPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
                SteamInterface.Cloud.Write("test123.dat", bufferPtr, 128);
            }
            finally
            {
                bufferHandle.Free();
            }
        }
        if (GUILayout.Button("Check Number of Files"))
        {
            ICloud cloud = SteamInterface.Cloud;
            Debug.Log("test123.dat Exists? " + cloud.Exists("test123.dat"));
        }
        if (GUILayout.Button("Read File"))
        {
            ICloud cloud     = Steamworks.SteamInterface.Cloud;
            string _filename = "test123.dat";
            int    filesize  = cloud.GetSize(_filename);
            Debug.Log("File Size: " + filesize);

            IntPtr hLocalRead = Marshal.AllocHGlobal(filesize);              // I am guessing this could be a problem line
            int    amountRead = cloud.Read(_filename, hLocalRead, filesize); // I am guessing this could be a problem line.
            Debug.Log("Amount Read: " + amountRead);

            String returnedString = Marshal.PtrToStringAnsi(hLocalRead);
            Debug.Log("Our Read Data is: " + returnedString);

            Marshal.FreeHGlobal(hLocalRead);
        }
        if (GUILayout.Button("Delete File"))
        {
            ICloud cloud = SteamInterface.Cloud;
            cloud.Delete("test123.dat");
            cloud.Forget("test123.dat");
        }

        GUILayout.Space(24);

        // NOTE!
        // Overlays might not work in the Unity editor, see the documentation for more information
        if (GUILayout.Button("Show overlay"))
        {
            // Will show the game overlay and show the Friends dialog.
            SteamInterface.Friends.ActivateGameOverlay(OverlayDialog.Friends);
        }
        if (GUILayout.Button("Show overlay (webpage)"))
        {
            // Will show the game overlay and open a web page.
            SteamInterface.Friends.ActivateGameOverlayToWebPage("http://ludosity.com");
        }
    }