public static void LoadProjectPageFromClipboard() { var collector = new ErrorCollector(); var project = Project.current; ProjectPage page = null; try { var text = SDL.SDL_GetClipboardText(); var compressedBytes = Convert.FromBase64String(text.Trim()); using (var deflateStream = new DeflateStream(new MemoryStream(compressedBytes), CompressionMode.Decompress)) { using (var ms = new MemoryStream()) { deflateStream.CopyTo(ms); var bytes = ms.GetBuffer(); var index = 0; if (DataUtils.ReadLine(bytes, ref index) != "YAFC" || DataUtils.ReadLine(bytes, ref index) != "ProjectPage") { throw new InvalidDataException(); } var version = new Version(DataUtils.ReadLine(bytes, ref index) ?? ""); if (version > YafcLib.version) { collector.Error("String was created with the newer version of YAFC (" + version + "). Data may be lost.", ErrorSeverity.Important); } DataUtils.ReadLine(bytes, ref index); // reserved 1 if (DataUtils.ReadLine(bytes, ref index) != "") // reserved 2 but this time it is requried to be empty { throw new NotSupportedException("Share string was created with future version of YAFC (" + version + ") and is incompatible"); } page = JsonUtils.LoadFromJson <ProjectPage>(new ReadOnlySpan <byte>(bytes, index, (int)ms.Length - index), project, collector); } } } catch (Exception ex) { collector.Exception(ex, "Clipboard text does not contain valid YAFC share string", ErrorSeverity.Critical); } if (page != null) { var existing = project.FindPage(page.guid); if (existing != null) { MessageBox.Show((haveChoice, choice) => { if (!haveChoice) { return; } if (choice) { project.RecordUndo().pages.Remove(existing); } else { page.GenerateNewGuid(); } project.RecordUndo().pages.Add(page); MainScreen.Instance.SetActivePage(page); }, "Page already exists", "Looks like this page already exists with name '" + existing.name + "'. Would you like to replace it or import as copy?", "Replace", "Import as copy"); } else { project.RecordUndo().pages.Add(page); MainScreen.Instance.SetActivePage(page); } } if (collector.severity > ErrorSeverity.None) { ErrorListPanel.Show(collector); } }