public static WorkingProject Parse(ProjectInfo project, Storage store, TextureStore textures, APIController api) { WorkingProject ret = new WorkingProject(ref project, textures, api?.LocalUser.Value.ID ?? 0); if (project.File != null) { try { if (GamesToGoEditor.HashBytes(System.IO.File.ReadAllBytes(store.GetFullPath($"files/{project.File.NewName}"))) != project.File.NewName) { return(null); } if (!ret.parse(System.IO.File.ReadAllLines(store.GetFullPath($"files/{project.File.NewName}")))) { return(null); } if (!ret.postParse()) { return(null); } } catch { if (Debugger.IsAttached) { throw; } return(null); } if (project.Relations != null) { if (project.Relations.Count != ret.Images.Count) { return(null); } if (project.Relations.Any(image => ret.Images.All(im => im.ImageName != image.File.NewName))) { return(null); } } } ret.ProjectElements.CollectionChanged += (_, _) => ret.updateDatabaseObjectInfo(); ret.updateDatabaseObjectInfo(); ret.lastSavedState = ret.stateHash(); return(ret); }
private void load(GameHost host) { game = new GamesToGoEditor { Anchor = Anchor.Centre, Origin = Anchor.Centre, FillAspectRatio = 1920f / 1080, RelativeSizeAxes = Axes.Both, FillMode = FillMode.Fit, Masking = true, }; game.SetHost(host); AddUntilStep("Wait for load", () => game.IsLoaded); AddStep("Toggle Draw Visualiser", () => browser.OnPressed(FrameworkAction.ToggleDrawVisualiser)); Add(game); }
private void selectProjectImage(string path) { var finalName = GamesToGoEditor.HashBytes(System.IO.File.ReadAllBytes(path)); var destinationPath = filesPath + finalName; DatabaseFile file; if (project.Images.Any(i => i.ImageName == finalName)) { ShowError(@"Esta imagen ya ha sido agregada"); return; } if (!store.Exists($"files/{finalName}")) { System.IO.File.Copy(path, destinationPath); } else if (GamesToGoEditor.HashBytes(System.IO.File.ReadAllBytes(destinationPath)) != finalName) { System.IO.File.Delete(destinationPath); System.IO.File.Copy(path, destinationPath); } if (database.Files.Any(f => f.NewName == finalName)) { file = database.Files.FirstOrDefault(f => f.NewName == finalName); } else { database.Add(file = new DatabaseFile { OriginalName = Path.GetFileName(path), NewName = finalName, Type = "image", }); } database.Add(new FileRelation { File = file, Project = project.DatabaseObject }); project.AddImage(file); Hide(); }
public void SaveProject(CommunityStatus communityStatus, bool showSplashConfirmation = true) { string fileString = workingProject.SaveableString(communityStatus); string newFileName; using (MemoryStream stream = new MemoryStream()) { var sw = new StreamWriter(stream, new UTF8Encoding()); sw.Write(fileString); sw.Flush(); stream.Seek(0, SeekOrigin.Begin); newFileName = GamesToGoEditor.HashBytes(stream.ToArray()); sw.Dispose(); } using (Stream fileStream = store.GetStream($"files/{newFileName}", FileAccess.Write, FileMode.Create)) { var sw = new StreamWriter(fileStream, new UTF8Encoding()); sw.Write(fileString); sw.Flush(); sw.Dispose(); } if (workingProject.DatabaseObject.File == null) { workingProject.DatabaseObject.File = new DatabaseFile { Type = "project", }; database.Add(workingProject.DatabaseObject); } else { store.Delete($"files/{workingProject.DatabaseObject.File.NewName}"); } workingProject.DatabaseObject.File.NewName = newFileName; database.SaveChanges(); workingProject.DatabaseObject.ImageRelationID = workingProject.Image.Value == null ? null : (int?)workingProject.DatabaseObject.Relations.First(r => r.File.NewName == workingProject.Image.Value.ImageName).RelationID; database.SaveChanges(); initialRelations = workingProject.DatabaseObject.Relations == null ? null : new List <FileRelation>(workingProject.DatabaseObject.Relations); Random random = new Random(); if (showSplashConfirmation) { splashOverlay.Show(@"Se ha guardado el proyecto localmente", new Colour4(randomNumber(), randomNumber(), randomNumber(), 255) /*new Colour4(80, 80, 80, 255)*/); } byte randomNumber() { return((byte)(random.NextDouble() * 255)); } }
private string stateHash() { return(GamesToGoEditor.HashBytes(Encoding.UTF8.GetBytes(stateString() + JsonConvert.SerializeObject(DatabaseObject)))); }