/// <exception cref="ArgumentNullException"><paramref name="archive"/> is <see langword="null" />.</exception> /// <exception cref="ArgumentException">Platform Mismatch: The operating system is not compatible with the archive files.</exception> /// <exception cref="ArchiveException"></exception> /// <exception cref="InvalidGameArchiveContentsException"></exception> /// <exception cref="UnauthorizedAccessException">The caller does not have the required permission.</exception> /// <exception cref="FailedToLaunchSevenZipException">The 7Zip executable could not be found or failed to launch.</exception> /// <exception cref="SevenZipExitCodeException">Seven zip returned with a bad exit code.</exception> public async Task InstallFromArchive(GameArchive archive) { if (archive == null) { throw new ArgumentNullException("archive"); } var currentOs = OperatingSystemEx.CurrentOS; var archiveOs = archive.Spec.OperatingSystem; if (currentOs != archiveOs) { throw new ArgumentException("Platform Mismatch: The operating system is not compatible with the archive files.", "archive"); } using (await _lock.LockAsync()) { _status.OnNext(InstallationStatus.Installing); try { await archive.Extract(_storageDirectory); } finally { RefreshStatusInternal(); } } }
void Awake() { D.EnableLog = true; TimeManager.GetInstance(); GameArchive.GetInstance().Read(); }
public void SaveGame() { hexCells = HexGrid.HexCells; GameArchive gameArchive = new GameArchive(RoleList, hexCells); string path = Application.dataPath + "/Data/Save/Save1.json"; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(Application.dataPath + "//Data//Save"); } gameArchive.Save(path); Debug.Log("保存完成"); }
public async Task InstallArchiveImpl() { /* * var archiveExtension = GameArchiveSpec.GetArchiveExtension(os); * * var zipDialog = new OpenFileDialog * { * AutoUpgradeEnabled = true, * CheckFileExists = true, * DefaultExt = archiveExtension, * SupportMultiDottedExtensions = true, * Filter = string.Format("Archive Files (*{0}) | *{0}", archiveExtension) * }; * * if (zipDialog.ShowDialog() != DialogResult.OK) * return; */ // Do this: http://stackoverflow.com/a/25630554 // Pass FileName or stream or something as an argument to the second command using Observable.Invoke if (InstallFileArchiveFilePath == null) { return; } var os = OperatingSystemEx.CurrentOS; var archiveSpec = new GameArchiveSpec(Model.Spec, os); try { var archive = new GameArchive(InstallFileArchiveFilePath, archiveSpec); await Model.InstallFromArchive(archive); } catch (UnauthorizedAccessException) { MessageBox.Show("Unauthorized access"); } catch (DirectoryNotFoundException) { MessageBox.Show("The specified path is invalid (for example, it is on an unmapped drive)."); } catch (IOException) { MessageBox.Show("The directory is a file.-or-The network name is not known."); } catch (SecurityException) { MessageBox.Show("Security exception"); } }
public void SaveDataToDrive() { GameObject gameObject = new GameObject("new game object"); Property newProperty = new Property(PropertyType.String, "new property", "new value"); gameObject.AddProperty(newProperty); GameObserver Observer = GameObserver.Instance; Observer.ObserveGameObject(gameObject, ObjectStatus.Active); GameData gameData = new GameData(Observer.GetObserverData()); GameArchive Archive = GameArchive.Instance; Archive.SaveData(gameData, "C:\\GameCraftData\\testgamedata.gcd"); Assert.IsTrue(true); }
public void LoadGame() { Empty(); string path = Application.dataPath + "/Data/Save/Save1.json"; GameArchive Archive = GameArchive.Load(path); if (Archive != null) { if (Archive.HexCellSerialization != null) { HexGrid.Init(Archive.X, Archive.Z); HexCellSerialization.CoverageHexMap(HexGrid.HexCells, Archive.HexCellSerialization); } Debug.Log("载入完成"); } }
private static void GameWorkOn(long gameProjectId, long gameArchiveId) { Task task = Task.Run(() => { GameManager gm = Games[gameProjectId]; DateTime lastSaveTime = DateTime.Now; // Основной цикл игры while (gm.GameStatus == GameStatusType.InProgress || gm.GameStatus == GameStatusType.Stopped) { // Просчитываем один фрейм игры gm.Iterate(); // Сохраняем игру, если прошло нужное время if (DateTime.Now > lastSaveTime.AddMinutes(SaveDelayMin)) { using (var db = new NiteLigaContext()) { GameArchive ga = db.GameArchives.Single(x => x.Id == gameArchiveId); ga.Log = gm.GetLastBackup(); db.SaveChanges(); } lastSaveTime = DateTime.Now; } // Делаем паузу Thread.Sleep(IterationDelayMs); } // Сохраняем время завершения игры и самый последний лог using (var db = new NiteLigaContext()) { GameArchive ga = db.GameArchives.Single(x => x.Id == gameArchiveId); ga.Log = gm.GetLastBackup(); ga.EndDate = DateTime.Now; db.SaveChanges(); } // Убираем игру из общего списка Games.Remove(gameProjectId); }); }
private void Open_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = filterstring; dlg.InitialDirectory = Properties.Settings.Default.lastOpenPath; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { if (archive != null) { archive.close(); archive = null; dataGrid1.ItemsSource = new List<FileRecord>(); Window.Title = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; } FileStream OpenFile = File.Open(dlg.FileName, FileMode.Open); foreach (GameArchive plugin in ArchivePlugins) { #if DEBUG Console.WriteLine("{0} attempting to open file", plugin); #endif OpenFile.Seek(0, SeekOrigin.Begin); if (plugin.LoadFile(OpenFile)) { archive = plugin; break; } } if (archive != null) { fileList = new List<FileRecord>(); for (int i = 0; i < archive.numFiles; i++) fileList.Add(new FileRecord(i, archive.getFileName(i), archive.getFileSize(i))); dataGrid1.ItemsSource = fileList; Properties.Settings.Default.lastOpenPath = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\')); Properties.Settings.Default.Save(); Window.Title = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " - " + dlg.FileName.Substring(dlg.FileName.LastIndexOf('\\') + 1); } else { MessageBox.Show("Unrecognized File Type", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }