Exemplo n.º 1
0
        private void InitConfig()
        {
            SystemConfig sc = UTIL.FILE.RestoreConfig <SystemConfig>(CONST.CONFIG_FILE, false);

            if (Object.ReferenceEquals(sc, null))
            {
                sc = new SystemConfig()
                {
                    robotConfig = CONST.DEFAULT_ROBOT_CONFIG
                };
            }

            if (!File.Exists(UTIL.FILE.GetConfigFileFullName(CONST.CONFIG_FILE)))
            {
                UTIL.FILE.SaveConfig(sc, CONST.CONFIG_FILE, false);
            }

            bool   configReady = false;
            string fullName    = UTIL.FILE.GetConfigFileFullName(sc.robotConfig);

            if (File.Exists(fullName))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(fullName);
                    configReady         = true;
                    SYSTEM.robotConfig  = sc.robotConfig;
                }
                catch { }
            }

            if ((!configReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.robotConfig  = "";
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;
        }
Exemplo n.º 2
0
        private void InitConfig()
        {
            SYSTEM.configPath       = MyUtil.FILE.AppFilePath(CONST.CONFIG_FOLDER);
            SYSTEM.systemConfigFile = Path.Combine(SYSTEM.configPath, CONST.SYSTEM_CONFIG);

            SYSTEM.sc = MyUtil.FILE.RestoreDataFile <SystemConfig>(SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            if (Object.ReferenceEquals(SYSTEM.sc, null))
            {
                SYSTEM.sc = new SystemConfig()
                {
                    robotConfigFile      = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE,
                    blocklyPath          = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH),
                    autoCheckVersion     = CONST.DEFAULT_CONFIG.AUTO_CHECK_VERSION,
                    autoCheckFirmware    = CONST.DEFAULT_CONFIG.AUTO_CHECK_FIRMWARE,
                    waitRebootSec        = CONST.DEFAULT_CONFIG.WAIT_REBOOT_SEC,
                    disableBatteryUpdate = CONST.DEFAULT_CONFIG.DISABLE_BATTERY_UPDATE,
                    disableMpuUpdate     = CONST.DEFAULT_CONFIG.DISABLE_MPU_UPDATE,
                    developerMode        = CONST.DEFAULT_CONFIG.DEVEOPER_MODE
                };
            }
            else
            {
                if (SYSTEM.sc.robotConfigFile == null)
                {
                    SYSTEM.sc.robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE;
                }
                if (String.IsNullOrWhiteSpace(SYSTEM.sc.blocklyPath))
                {
                    SYSTEM.sc.blocklyPath = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH);
                }
            }

            // fill default for invalid value, to handle for reading from old config files
            if ((SYSTEM.sc.waitRebootSec == 0) || (SYSTEM.sc.waitRebootSec > 99))
            {
                SYSTEM.sc.waitRebootSec = CONST.DEFAULT_CONFIG.WAIT_REBOOT_SEC;
            }

            // Check blockly path

            if (!Util.IsBlocklyPath(SYSTEM.sc.blocklyPath))
            {
                if (!Util.IsBlocklyPath(MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH)))
                {
                    SYSTEM.sc.blocklyPath = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH);
                }
            }

            #region "Version Config"

            if (SYSTEM.sc.autoCheckFirmware)
            {
                Util.CheckFirmware();
            }
            else
            {
                SYSTEM.firmwareChecked = false;
            }

            #endregion


            #region "Get Robot Config"

            if (!File.Exists(SYSTEM.systemConfigFile))
            {
                MyUtil.FILE.SaveDataFile(SYSTEM.sc, SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            }

            bool   robotConfigReady = false;
            string robotConfigFile  = Path.Combine(SYSTEM.configPath, SYSTEM.sc.robotConfigFile);
            if (File.Exists(robotConfigFile))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(robotConfigFile);
                    robotConfigReady    = true;
                }
                catch { }
            }

            if ((!robotConfigReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;

            #endregion

            if (!File.Exists(Path.Combine(SYSTEM.sc.blocklyPath, CONST.BLOCKLY.CHECK_FILE)))
            {
                SYSTEM.sc.blocklyPath = "";
            }

            Util.SaveSystemConfig();
        }
Exemplo n.º 3
0
        private void InitConfig()
        {
            SYSTEM.configPath       = MyUtil.FILE.AppFilePath(CONST.CONFIG_FOLDER);
            SYSTEM.systemConfigFile = Path.Combine(SYSTEM.configPath, CONST.SYSTEM_CONFIG);

            SYSTEM.sc = MyUtil.FILE.RestoreDataFile <SystemConfig>(SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            if (Object.ReferenceEquals(SYSTEM.sc, null))
            {
                SYSTEM.sc = new SystemConfig()
                {
                    robotConfigFile      = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE,
                    blocklyPath          = CONST.DEFAULT_CONFIG.BLOCKLY_PATH,
                    autoCheckVersion     = CONST.DEFAULT_CONFIG.AUTO_CHECK_VERSION,
                    autoCheckFirmware    = CONST.DEFAULT_CONFIG.AUTO_CHECK_FIRMWARE,
                    disableBatteryUpdate = CONST.DEFAULT_CONFIG.DISABLE_BATTERY_UPDATE,
                    disableMpuUpdate     = CONST.DEFAULT_CONFIG.DISABLE_MPU_UPDATE,
                    developerMode        = CONST.DEFAULT_CONFIG.DEVEOPER_MODE
                };
            }
            else
            {
                if (SYSTEM.sc.robotConfigFile == null)
                {
                    SYSTEM.sc.robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE;
                }
                if (SYSTEM.sc.blocklyPath == null)
                {
                    SYSTEM.sc.blocklyPath = CONST.DEFAULT_CONFIG.BLOCKLY_PATH;
                }
            }

            #region "Version Config"

            SYSTEM.versionChecked = false;
            if (SYSTEM.sc.autoCheckVersion)
            {
            }

            if (SYSTEM.sc.autoCheckFirmware)
            {
                Util.CheckFirmware();
            }
            else
            {
                SYSTEM.firmwareChecked = false;
            }

            #endregion


            #region "Get Robot Config"

            if (!File.Exists(SYSTEM.systemConfigFile))
            {
                MyUtil.FILE.SaveDataFile(SYSTEM.sc, SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            }

            bool   robotConfigReady = false;
            string robotConfigFile  = Path.Combine(SYSTEM.configPath, SYSTEM.sc.robotConfigFile);
            if (File.Exists(robotConfigFile))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(robotConfigFile);
                    robotConfigReady    = true;
                }
                catch { }
            }

            if ((!robotConfigReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;

            #endregion

            if (!File.Exists(Path.Combine(SYSTEM.sc.blocklyPath, CONST.BLOCKLY.CHECK_FILE)))
            {
                SYSTEM.sc.blocklyPath = "";
            }

            Util.SaveSystemConfig();
        }