コード例 #1
0
        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
        }
コード例 #2
0
        /// <summary>
        /// Loads a config
        /// </summary>
        /// <param name="loadedConfig">the config to populate</param>
        /// <returns>true if successfully loaded, otherwise false</returns>
        public static bool LoadVisualFromFile(out VisualConfig loadedConfig, string fileName)
        {
            bool   fileExists = false;
            string filePath;
            bool   eepromFound = false;
            string configStr;

            loadedConfig = new VisualConfig();
#if !EEPROM_DISABLED
            configStr = EEPROMCalibration.LoadConfigFromEEPROM();
            if (configStr != "")
            {
                eepromFound = true;
                try
                {
                    loadedConfig = JsonUtility.FromJson <VisualConfig>(configStr);
                }
                catch
                {
                    eepromFound = false;
                }
            }

            if (eepromFound)
            {
                //Debug.Log(Misc.debugLogText + "Config loaded! loaded from device memory");
                loadedConfig.loadedFrom = "Serial Flash / EEPROM";
            }
            else
            {
#if !UNITY_EDITOR
                Debug.Log(Misc.debugLogText + "Failed to load config file from device memory.");
#endif
            }
#endif
            if (!eepromFound)
            {
                if (!GetConfigPathToFile(Path.Combine(configDirName, fileName), out filePath))
                {
// #if UNITY_EDITOR_WIN
//                     if (Multidisplay.GetNumberOfDisplays() != 1)
// #endif
                    Debug.LogWarning(Misc.debugLogText + "Config file not found!");
                }
                else
                {
                    configStr = File.ReadAllText(filePath);
                    if (configStr.IndexOf('{') < 0 || configStr.IndexOf('}') < 0)
                    {
                        // if the file exists but is unpopulated by any info, don't try to parse it
                        // this is a bug with jsonUtility that it doesn't know how to handle a fully empty text file >:(
                        Debug.LogWarning(Misc.debugLogText + "Config file not found!");
                    }
                    else
                    {
                        // if it's made it this far, just load it
                        fileExists = true;
                        Debug.Log(Misc.debugLogText + "Config loaded! loaded from " + filePath);
                        loadedConfig            = JsonUtility.FromJson <VisualConfig>(configStr);
                        loadedConfig.loadedFrom = filePath;
                    }
                }
            }
            // make sure test value is always 0 unless specified by calibrator
            // inverted viewcone is handled separately now, so just take the abs of it
            loadedConfig.viewCone.Value = Mathf.Abs(loadedConfig.viewCone.Value);

            // note: instance static ref is legacy
            instance = loadedConfig;

            return(fileExists || eepromFound);
        }
コード例 #3
0
        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
        }
コード例 #4
0
        /// <summary>
        /// Loads a config
        /// </summary>
        /// <param name="loadedConfig">the config to populate</param>
        /// <returns>true if successfully loaded, otherwise false</returns>
        public static bool LoadVisualFromFile(out VisualConfig loadedConfig, string fileName)
        {
            loadedConfig = new VisualConfig();
            bool   fileExists = false;
            string filePath;
            bool   eepromFound = false;

#if EEPROM_CALIB_ENABLE
            int ret = EEPROMCalibration.LoadConfigFromEEPROM(ref loadedConfig);
            if (ret == 0)
            {
                Debug.Log(Misc.warningText + "Config file loaded from device memory.");
                loadedConfig.loadedFrom = "Device memory";
                // calibration loaded successfully!
                // EEPROMCalibration.PrintConfig(hpc);
                eepromFound = true;
            }
            else if (ret < -5)
            {
                // if ret = -6, the calibration was loaded but the version number didn't match
                // if ret = -5, data was loaded from EEPROM but not recognized as a calibration file
                //     (this will happen whenever the HoloPlayConfig changes in size, for instance if you change a float to an int)
            }
            if (ret < 0)
            {
                // if ret = -4, -3, -2, or -1, we couldn't open the HID pipe
            }
#endif
            if (!eepromFound)
            {
                if (!GetConfigPathToFile(Path.Combine(configDirName, fileName), out filePath))
                {
                    Debug.LogWarning(Misc.warningText + "Config file not found!");
                }
                else
                {
                    string configStr = File.ReadAllText(filePath);
                    if (configStr.IndexOf('{') < 0 || configStr.IndexOf('}') < 0)
                    {
                        // if the file exists but is unpopulated by any info, don't try to parse it
                        // this is a bug with jsonUtility that it doesn't know how to handle a fully empty text file >:(
                        Debug.LogWarning(Misc.warningText + "Config file not found!");
                    }
                    else
                    {
                        // if it's made it this far, just load it
                        fileExists = true;
                        Debug.Log(Misc.warningText + "Config loaded! loaded from " + filePath);
                        loadedConfig            = JsonUtility.FromJson <VisualConfig>(configStr);
                        loadedConfig.loadedFrom = filePath;
                    }
                }
            }
            // make sure test value is always 0 unless specified by calibrator
            // inverted viewcone is handled separately now, so just take the abs of it
            loadedConfig.viewCone.Value = Mathf.Abs(loadedConfig.viewCone.Value);

            // note: instance static ref is legacy
            instance = loadedConfig;

            return(fileExists || eepromFound);
        }