public static void UpgradeWorld(string directoryName)
        {
            WorldInfo worldInfo = WorldsManager.GetWorldInfo(directoryName);

            if (worldInfo == null)
            {
                object[] objArray1 = new object[] { directoryName };
                throw new InvalidOperationException(string.Format("Cannot determine version of world at \"{0}\"", (object[])objArray1));
            }
            if (worldInfo.SerializationVersion != SerializationVersion)
            {
                object[] objArray2 = new object[] { SerializationVersion };
                ProgressManager.UpdateProgress(string.Format("Upgrading World To {0}", (object[])objArray2), 0f);
                List <VersionConverter> list = FindTransform(worldInfo.SerializationVersion, SerializationVersion, (IEnumerable <VersionConverter>)m_versionConverters, 0);
                if (list == null)
                {
                    object[] objArray3 = new object[] { worldInfo.SerializationVersion, SerializationVersion };
                    throw new InvalidOperationException(string.Format("Cannot find conversion path from version \"{0}\" to version \"{1}\"", (object[])objArray3));
                }
                foreach (VersionConverter converter in list)
                {
                    object[] objArray4 = new object[] { converter.SourceVersion, converter.TargetVersion };
                    Log.Information(string.Format("Upgrading world version \"{0}\" to \"{1}\".", (object[])objArray4));
                    converter.ConvertWorld(directoryName);
                }
                WorldInfo info2 = WorldsManager.GetWorldInfo(directoryName);
                if (info2.SerializationVersion != SerializationVersion)
                {
                    object[] objArray5 = new object[] { SerializationVersion, info2.SerializationVersion };
                    throw new InvalidOperationException(string.Format("Upgrade produced invalid project version. Expected \"{0}\", found \"{1}\".", (object[])objArray5));
                }
                AnalyticsParameter[] parameters = new AnalyticsParameter[] { new AnalyticsParameter("SourceVersion", worldInfo.SerializationVersion), new AnalyticsParameter("TargetVersion", SerializationVersion) };
                AnalyticsManager.LogEvent("[VersionConverter] Upgrade world", parameters);
            }
        }
        public static void UpgradeWorld(string directoryName)
        {
            WorldInfo worldInfo = WorldsManager.GetWorldInfo(directoryName);

            if (worldInfo == null)
            {
                throw new InvalidOperationException($"Cannot determine version of world at \"{directoryName}\"");
            }
            if (worldInfo.SerializationVersion != SerializationVersion)
            {
                ProgressManager.UpdateProgress($"Upgrading World To {SerializationVersion}", 0f);
                foreach (VersionConverter item in FindTransform(worldInfo.SerializationVersion, SerializationVersion, m_versionConverters, 0) ?? throw new InvalidOperationException($"Cannot find conversion path from version \"{worldInfo.SerializationVersion}\" to version \"{SerializationVersion}\""))
                {
                    Log.Information($"Upgrading world version \"{item.SourceVersion}\" to \"{item.TargetVersion}\".");
                    item.ConvertWorld(directoryName);
                }
                WorldInfo worldInfo2 = WorldsManager.GetWorldInfo(directoryName);
                if (worldInfo2.SerializationVersion != SerializationVersion)
                {
                    throw new InvalidOperationException($"Upgrade produced invalid project version. Expected \"{SerializationVersion}\", found \"{worldInfo2.SerializationVersion}\".");
                }
                AnalyticsManager.LogEvent("[VersionConverter] Upgrade world", new AnalyticsParameter("SourceVersion", worldInfo.SerializationVersion), new AnalyticsParameter("TargetVersion", SerializationVersion));
            }
        }
Beispiel #3
0
 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));
         }
     }));
 }