public DynamicKeyboardFolder()
        {
            // Find all possible xml files
            string filePath = Settings.Default.DynamicKeyboardsLocation;

            keyboards = new List <KeyboardInfo>();

            if (Directory.Exists(filePath))
            {
                string[] fileArray = Directory.GetFiles(filePath, "*.xml");

                Log.InfoFormat("Found {0} keyboard files", fileArray.Length);

                // Read in keyboard name, symbol, hidden state from each file
                // Note that ordering is currently undefined
                foreach (string fileName in fileArray)
                {
                    string       keyboardPath = Path.Combine(filePath, fileName);
                    KeyboardInfo info         = GetKeyboardInfo(keyboardPath);
                    if (null != info.fullPath)
                    {
                        if (!info.isHidden)
                        {
                            keyboards.Add(info);
                            Log.InfoFormat("Found keyboard file: {0}", info.fullPath);
                        }
                        else
                        {
                            Log.InfoFormat("Ignoring keyboard file: {0}", info.fullPath);
                        }
                    }
                }
            }
        }
        // get name from XML if present
        private KeyboardInfo GetKeyboardInfo(string keyboardPath)
        {
            KeyboardInfo info = new KeyboardInfo();

            info.fullPath = keyboardPath;

            try
            {
                XmlKeyboard spec = XmlKeyboard.ReadFromFile(keyboardPath);

                info.keyboardName = DynamicKeyboard.StringWithValidNewlines(spec.Name);
                info.symbolString = spec.Symbol;
                info.isHidden     = spec.Hidden;

                // default to filename if no name given
                if (info.keyboardName.Length == 0)
                {
                    info.keyboardName = Path.GetFileName(keyboardPath);
                }
            }
            catch (Exception e)
            {
                // replace info with default (no contents)
                info = new KeyboardInfo();
                Log.Error(e.ToString());
            }

            return(info);
        }
Esempio n. 3
0
        public DynamicKeyboardFolder(String filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                filePath = Settings.Default.DynamicKeyboardsLocation;
            }

            keyboards = new List <KeyboardInfo>();

            // Find all possible xml files
            if (Directory.Exists(filePath))
            {
                string[] fileArray = Directory.GetFiles(filePath, "*.xml");

                Log.InfoFormat("Found {0} keyboard files", fileArray.Length);

                // Read in keyboard name, symbol, hidden state from each file
                // Note that ordering is currently undefined
                foreach (string fullName in fileArray)
                {
                    KeyboardInfo info = GetKeyboardInfo(fullName);
                    if (null != info.fullPath)
                    {
                        if (!info.isHidden)
                        {
                            keyboards.Add(info);
                            Log.InfoFormat("Found keyboard file: {0}", info.fullPath);
                        }
                        else
                        {
                            Log.InfoFormat("Ignoring keyboard file: {0}", info.fullPath);
                        }
                    }
                }

                // Look for any subdirs
                string[] folderArray = Directory.GetDirectories(filePath);
                foreach (string fullPath in folderArray)
                {
                    KeyboardInfo info       = GetKeyboardInfo(fullPath);
                    string       folderName = new DirectoryInfo(fullPath).Name;
                    if (null != info.fullPath && !folderName.StartsWith("."))
                    {
                        keyboards.Add(info);
                        Log.InfoFormat("Found keyboard folder: {0}", info.fullPath);
                    }
                }
            }
        }