예제 #1
0
        public void HandlePlists(string[] inputFiles)
        {
            var results    = new Dictionary <FileInfo, Claunia.PropertyList.NSObject>();
            var errorCount = 0;

            foreach (var file in inputFiles)
            {
                try
                {
                    var plist = Claunia.PropertyList.PropertyListParser.Parse(file);
                    results.Add(new FileInfo(file), plist);
                }
                catch
                {
                    errorCount++;
                }
            }

            if (errorCount > 0)
            {
                MainWindowRef.ShowMessageAsync("Error FYI", $"A total of {errorCount} error(s) occurred while parsing items.");
            }

            var output = new List <PlistViewModel>();

            foreach (var item in results)
            {
                var nPlist = new PlistViewModel()
                {
                    Name            = item.Key.Name,
                    Content         = JsonConvert.SerializeObject(item.Value, Formatting.Indented),
                    sourceFile      = item.Key,
                    assocCheatSheet = CheatSheetEntries.FirstOrDefault(x => x.File.Equals(item.Key.Name, StringComparison.CurrentCultureIgnoreCase)),
                };

                if (nPlist.assocCheatSheet == null)
                {
                    var regexList = CheatSheetEntries.Where(x => x.File.Contains("*"));
                    foreach (var rgpattern in regexList)
                    {
                        if (Regex.IsMatch(nPlist.Name, rgpattern.File.Replace("*", @"[\w\W]*?").Replace(".", @"\.")))
                        {
                            nPlist.assocCheatSheet = rgpattern;
                            break;
                        }
                    }
                }

                LoadedData.Add(nPlist);
            }


            // Just to update our counts
            NotifyPropertyChanged("LoadedFilesCVS");
            return;
        }