Exemplo n.º 1
0
        public static void GetContentList(string titleId, Action <bool, List <ContentInfo> > callback)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            var task = PlayFabAdminAPI.GetContentListAsync(new GetContentListRequest())
                       .ContinueWith(
                (result) =>
            {
                PlayFabSettings.TitleId            = currentPlayFabTitleId;
                PlayFabSettings.DeveloperSecretKey = currentDevKey;
                if (result.Result.Error != null)
                {
                    Console.WriteLine(PlayFabUtil.GetErrorReport(result.Result.Error));
                    callback(false, null);
                    return;
                }
                if (result.IsCompleted)
                {
                    callback(true, result.Result.Result.Contents);
                }
            });
        }
Exemplo n.º 2
0
        async public static Task <List <ContentInfo> > GetContentList(string titleId)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            var result = await PlayFabAdminAPI.GetContentListAsync(new GetContentListRequest());

            PlayFabSettings.TitleId            = currentPlayFabTitleId;
            PlayFabSettings.DeveloperSecretKey = currentDevKey;
            if (result.Error != null)
            {
                Console.WriteLine(PlayFabUtil.GetErrorReport(result.Error));
                return(null);
            }

            return(result.Result.Contents);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            _MetaStateSettings.Init();

            bool isCdnOnlyMode = false;


            List <string> allArgs = args == null ? new List <string>() : args.ToList();

            PlayFab.PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabSettings.DeveloperSecretKey;
            PlayFab.PlayFabSettings.staticSettings.TitleId            = PlayFabSettings.TitleId;

            BackOfficeStatusUrl = AzureSettings.StatusUrl;

            if (allArgs.Contains("-cdnonly"))
            {
                isCdnOnlyMode = true;
                Console.WriteLine("Found -cdnonly switch, will only sync files...");
            }


            if (allArgs.ElementAtOrDefault(0) != null && allArgs.ElementAtOrDefault(0) == "-appversion")
            {
                string version = allArgs.ElementAtOrDefault(1);
                string path    = allArgs.ElementAtOrDefault(2);

                if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(path))
                {
                    File.WriteAllText(path, version);
                }

                return;
            }

            if (allArgs.ElementAtOrDefault(0) != null && allArgs.ElementAtOrDefault(0) == "-status")
            {
                bool   online  = allArgs.ElementAtOrDefault(1) == "online" ? true : false;
                string seconds = allArgs.ElementAtOrDefault(2);

                string version = allArgs.ElementAtOrDefault(3);

                ChangeServerStatus(online, seconds, version);
                return;
            }


            var pathArg = allArgs.Where(y => y.StartsWith("-BaseUnityFolder:")).SingleOrDefault();

            if (pathArg != null)
            {
                MetaStateSettings._BaseUnityFolder = pathArg.Replace("-BaseUnityFolder:", string.Empty);
            }


            var currentManifestResult = PlayFab.PlayFabServerAPI.GetTitleDataAsync(new PlayFab.ServerModels.GetTitleDataRequest()
            {
                Keys = new List <string>()
                {
                    MetaStateSettings._TitleDataKey_CdnManifest
                }
            }).GetAwaiter().GetResult();

            Console.WriteLine("Fetching CDN content...");
            AssetManifest currentManifest = null;

            if (currentManifestResult.Result.Data.ContainsKey(MetaStateSettings._TitleDataKey_CdnManifest) && !string.IsNullOrEmpty(currentManifestResult.Result.Data[MetaStateSettings._TitleDataKey_CdnManifest]))
            {
                currentManifest = JsonConvert.DeserializeObject <AssetManifest>(currentManifestResult.Result.Data[MetaStateSettings._TitleDataKey_CdnManifest]);
            }
            else
            {
                currentManifest = new AssetManifest();
            }

            Console.WriteLine("Loading local files on " + MetaStateSettings._BaseUnityFolder + MetaStateSettings._DownloadableFolderPath);
            List <AssetFileInfo> allFiles = LocalFileHandler.GetLocalDownloadableFiles();

            var allCdnContent = PlayFabAdminAPI.GetContentListAsync(new PlayFab.AdminModels.GetContentListRequest()).GetAwaiter().GetResult();



            int           currentDataVersion;
            AssetFileInfo previousDbFileInfo = null;

            if (!isCdnOnlyMode)
            {
                //string databasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + MetaStateSettings._DatabaseName;

                string databasePath = MetaStateSettings._BaseUnityFolder + MetaStateSettings._DatabaseFileName;



                DataLayer.Instance.Init(databasePath);
                currentDataVersion = DataLayer.Instance.GetTable <DataVersion>().First().Version;
                DataLayer.Instance.Connection.Close();

                var databaseFileInfo = new AssetFileInfo(databasePath, MetaStateSettings._AssetManagerStartupFolder + Path.GetFileName(databasePath) + MetaStateSettings._AssetManagerVersionString + currentDataVersion.ToString(), true);

                if (currentManifest.DataVersion != currentDataVersion)
                {
                    databaseFileInfo.ForceSync = true;
                }

                allFiles.Add(databaseFileInfo);
            }
            else
            {
                currentDataVersion = currentManifest.DataVersion;
                string dbFilename = MetaStateSettings._AssetManagerStartupFolder + MetaStateSettings._DatabaseName + MetaStateSettings._AssetManagerVersionString + currentDataVersion.ToString();
                previousDbFileInfo = currentManifest.Files.Where(y => y.RelativeName == dbFilename).SingleOrDefault();

                if (previousDbFileInfo != null)
                {
                    Console.WriteLine("Will re-import " + previousDbFileInfo.RelativeName + " to manifest...");
                }
            }


            List <AssetFileInfo> allFilesToBeSynced = new List <AssetFileInfo>();

            foreach (var file in allFiles)
            {
                var cdnFile      = allCdnContent.Result.Contents.Where(y => y.Key == file.RelativeName).SingleOrDefault();
                var playFabEntry = currentManifest.GetFile(file.RelativeName);
                if (playFabEntry == null || cdnFile == null || playFabEntry.Size != file.Size || file.ForceSync)
                {
                    allFilesToBeSynced.Add(file);
                    Console.WriteLine(file.RelativeName + " must be synced.");
                }
            }

            if (allFilesToBeSynced.Count > 0)
            {
                Console.WriteLine(string.Format("{0} file(s) must be synced. Press 1 to sync, 0 to cancel:", allFilesToBeSynced.Count.ToString()));


                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.D1:
                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine("Starting CDN Sync...");
                    bool hasError = false;
                    int  i        = 1;
                    foreach (var file in allFilesToBeSynced)
                    {
                        Console.WriteLine(string.Format("Uploading file {0} of {1}. ({2})", i.ToString(), allFilesToBeSynced.Count.ToString(), file.RelativeName));
                        if (!UploadFileToCDN(file.RelativeName, file.ToArray()))
                        {
                            hasError = true;
                            Console.WriteLine(string.Format("ERROR UPLOADING {0} of {1}. ({2})", i.ToString(), allFilesToBeSynced.Count.ToString(), file.RelativeName));
                            break;
                        }

                        i++;
                    }

                    if (!hasError)
                    {
                        Console.WriteLine("All files uploaded...");
                        Console.WriteLine("Creating and uploading manifest...");

                        currentManifest.ManifestVersion++;
                        currentManifest.DataVersion = currentDataVersion;
                        currentManifest.Files       = new List <AssetFileInfo>();
                        currentManifest.Files.AddRange(allFiles);

                        if (previousDbFileInfo != null)
                        {
                            currentManifest.Files.Add(previousDbFileInfo);
                        }

                        var updateData = PlayFabServerAPI.SetTitleDataAsync(new PlayFab.ServerModels.SetTitleDataRequest()
                        {
                            Key = MetaStateSettings._TitleDataKey_CdnManifest, Value = currentManifest.ToJson()
                        }).GetAwaiter().GetResult();
                        if (updateData.Error == null)
                        {
                            Console.WriteLine("Mafinest uploaded.");
                            Console.WriteLine("CDN Sync is COMPLETED.");
                        }
                        else
                        {
                            Console.WriteLine("Mafinest uploaded failed.");
                        }
                    }
                    break;
                }
            }
            else
            {
                Console.WriteLine("No files to be synced!");
            }

            //Console.WriteLine("Bruh, press any key to exit program.");
            //Console.ReadKey();
        }