Example #1
0
        public static KeyFile GetCurrentKeyFile()
        {
            KeyFile toReturn          = null;
            string  falconKeyFilePath = null;

            using (var reader = new F4SharedMem.Reader())
            {
                falconKeyFilePath = reader.GetCurrentData()?.StringData?.data?.Where(x => x.strId == (uint)F4SharedMem.Headers.StringIdentifier.KeyFile).First().value;
            }
            if (string.IsNullOrEmpty(falconKeyFilePath))
            {
                return(null);
            }
            var keyFileInfo = new FileInfo(falconKeyFilePath);

            if (!keyFileInfo.Exists)
            {
                return(null);
            }
            try
            {
                toReturn = KeyFile.Load(falconKeyFilePath);
            }
            catch (IOException e)
            {
                Log.Error(e.Message, e);
            }
            return(toReturn);
        }
Example #2
0
        private void LoadKeyFile(string keyFileName)
        {
            if (string.IsNullOrEmpty(keyFileName))
            {
                throw new ArgumentNullException("keyFileName");
            }
            var file = new FileInfo(keyFileName);

            if (!file.Exists)
            {
                throw new FileNotFoundException(keyFileName);
            }

            var oldViewerState = (ViewerState)_viewerState.Clone();

            try
            {
                _viewerState.Filename = keyFileName;
                _viewerState.KeyFile  = KeyFile.Load(keyFileName);
                ParseKeyFile();
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("An error occurred while loading the file.\n\n {0}", e.Message),
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                _viewerState = oldViewerState;
            }
        }
Example #3
0
        public static KeyFile GetCurrentKeyFile()
        {
            KeyFile toReturn    = null;
            var     exeFilePath = Util.GetFalconExePath();

            if (exeFilePath == null)
            {
                return(null);
            }
            var callsign = CallsignUtils.DetectCurrentCallsign();


            var configFolder = Path.GetDirectoryName(exeFilePath) + Path.DirectorySeparatorChar
                               + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar +
                               USEROPTS_DIRECTORY_NAME + Path.DirectorySeparatorChar + CONFIG_DIRECTORY_NAME;

            var pilotOptionsPath = configFolder + Path.DirectorySeparatorChar + callsign +
                                   PLAYER_OPTS_FILE_EXTENSION;

            if (!new FileInfo(pilotOptionsPath).Exists)
            {
                pilotOptionsPath = configFolder + Path.DirectorySeparatorChar + PLAYER_OPTS_FILENAME__DEFAULT;
            }


            string keyFileName = null;

            if (new FileInfo(pilotOptionsPath).Exists)
            {
                keyFileName = GetKeyFileNameFromPlayerOpts(pilotOptionsPath);
            }
            if (keyFileName == null)
            {
                keyFileName = KEYSTROKE_FILE_NAME__DEFAULT;
            }

            var falconKeyFilePath = configFolder + Path.DirectorySeparatorChar + keyFileName;
            var keyFileInfo       = new FileInfo(falconKeyFilePath);

            if (!keyFileInfo.Exists)
            {
                keyFileName       = KEYSTROKE_FILE_NAME__FALLBACK;
                falconKeyFilePath = configFolder + Path.DirectorySeparatorChar + keyFileName;
                keyFileInfo       = new FileInfo(falconKeyFilePath);
            }

            if (!keyFileInfo.Exists)
            {
                keyFileName       = KEYSTROKE_FILE_NAME__FALLBACK2;
                falconKeyFilePath = configFolder + Path.DirectorySeparatorChar + keyFileName;
                keyFileInfo       = new FileInfo(falconKeyFilePath);
            }

            if (!keyFileInfo.Exists)
            {
                return(null);
            }
            try
            {
                toReturn = KeyFile.Load(falconKeyFilePath);
            }
            catch (IOException e)
            {
                Log.Error(e.Message, e);
            }
            return(toReturn);
        }