public static void SaveVisualToFile(VisualConfig configToSave, string fileName, bool eeprom = true) { #if EEPROM_CALIB_ENABLE if (eeprom) { /****** save config to EEPROM ******/ int ret = EEPROMCalibration.WriteConfigToEEPROM(configToSave); if (ret == 0) { // EEPROM saving was successful Debug.Log(Misc.warningText + "Calibration saved to memory on device."); return; } else { // EEPROM saving was unsuccesful. Debug.Log(Misc.warningText + "Onboard calibration save failed."); } } #endif string filePath; if (!GetConfigPathToFile(Path.Combine(configDirName, fileName), out filePath)) { // ? throw a big, in-game visible warning if this fails Debug.LogWarning(Misc.warningText + "Unable to save config!"); return; } // Debug.Log(filePath + " \n is the filepath"); string json = JsonUtility.ToJson(configToSave, true); File.WriteAllText(filePath, json); Debug.Log(Misc.warningText + "Config saved!"); #if UNITY_EDITOR if (UnityEditor.PlayerSettings.defaultScreenWidth != configToSave.screenW.asInt || UnityEditor.PlayerSettings.defaultScreenHeight != configToSave.screenH.asInt) { UnityEditor.PlayerSettings.defaultScreenWidth = configToSave.screenW.asInt; UnityEditor.PlayerSettings.defaultScreenHeight = configToSave.screenH.asInt; } #endif }
public static void SaveVisualToFile(VisualConfig configToSave, string fileName, bool eeprom = true) { #if !EEPROM_DISABLED if (eeprom) { /****** save config to EEPROM ******/ int ret = EEPROMCalibration.WriteConfigToEEPROM(configToSave); if (ret == 0) { // EEPROM saving was successful Debug.Log(Misc.debugLogText + "Calibration saved to memory on device."); return; } else { // EEPROM saving was unsuccesful. Debug.Log(Misc.debugLogText + "Onboard calibration save failed."); } } #endif string filePath; if (!GetConfigPathToFile(Path.Combine(configDirName, fileName), out filePath)) { // ? throw a big, in-game visible warning if this fails Debug.LogWarning(Misc.debugLogText + "Unable to save config to drive!"); return; } // Debug.Log(filePath + " \n is the filepath"); string json = JsonUtility.ToJson(configToSave, true); File.WriteAllText(filePath, json); Debug.Log(Misc.debugLogText + "Config saved to " + filePath); #if CALIBRATOR if (BackupHandler.Instance != null) { var b = BackupHandler.Instance; for (int i = 0; i < b.drives.Count; i++) { var d = b.drives[i]; var dActive = b.backupActive[i]; if (dActive) { var lkgBackup = Path.Combine(d, "LKG_backup"); if (!Directory.Exists(lkgBackup)) { Directory.CreateDirectory(lkgBackup); } var backupNumber = Path.Combine(lkgBackup, configToSave.serial); if (!Directory.Exists(backupNumber)) { Directory.CreateDirectory(backupNumber); } var backupDirName = Path.Combine(backupNumber, configDirName); if (!Directory.Exists(backupDirName)) { Directory.CreateDirectory(backupDirName); } var backupFilePath = Path.Combine(backupDirName, visualFileName); File.WriteAllText(backupFilePath, json); Debug.Log(Misc.debugLogText + "Config backed up to " + backupFilePath); } } } #endif #if UNITY_EDITOR if (UnityEditor.PlayerSettings.defaultScreenWidth != configToSave.screenW.asInt || UnityEditor.PlayerSettings.defaultScreenHeight != configToSave.screenH.asInt) { UnityEditor.PlayerSettings.defaultScreenWidth = configToSave.screenW.asInt; UnityEditor.PlayerSettings.defaultScreenHeight = configToSave.screenH.asInt; } #endif }