コード例 #1
0
ファイル: Lib.cs プロジェクト: yrenlai/VBASync
        public static IList <KeyValuePair <string, Tuple <string, ModuleType> > > GetFolderModules(string folderPath)
        {
            var modulesText = new Dictionary <string, Tuple <string, ModuleType> >();
            var extensions  = new[] { ".bas", ".cls", ".frm" };
            var projIni     = new ProjectIni(Path.Combine(folderPath, "Project.INI"));

            if (File.Exists(Path.Combine(folderPath, "Project.INI.local")))
            {
                projIni.AddFile(Path.Combine(folderPath, "Project.INI.local"));
            }
            var projEncoding = Encoding.GetEncoding(projIni.GetInt("General", "CodePage") ?? Encoding.Default.CodePage);

            foreach (var filePath in Directory.GetFiles(folderPath, "*.*").Where(s => extensions.Any(s.EndsWith)).Select(s => Path.Combine(folderPath, Path.GetFileName(s))))
            {
                var moduleText = File.ReadAllText(filePath, projEncoding).TrimEnd('\r', '\n') + "\r\n";
                modulesText[Path.GetFileNameWithoutExtension(filePath)] = Tuple.Create(moduleText, ModuleProcessing.TypeFromText(moduleText));
            }
            return(modulesText.ToList());
        }
コード例 #2
0
        public IList <KeyValuePair <string, Tuple <string, ModuleType> > > GetCodeModules()
        {
            var modulesText = new Dictionary <string, Tuple <string, ModuleType> >();

            var projIni = new ProjectIni(_so.PathCombine(FolderPath, "Project.ini"));

            projIni.AddFile(_so.PathCombine(FolderPath, "Project.ini.local"));
            ProjectEncoding = Encoding.GetEncoding(projIni.GetInt("General", "CodePage") ?? Encoding.Default.CodePage);
            // no need to re-read projIni, since we only wanted to get the encoding off of it anyway!

            ModuleFilePaths = GetModuleFilePaths();
            foreach (var filePath in ModuleFilePaths)
            {
                var ext = _so.PathGetExtension(filePath).ToUpperInvariant();
                if (ext == ".BAS" || ext == ".CLS" || ext == ".FRM")
                {
                    var moduleText = _so.FileReadAllText(filePath, ProjectEncoding).TrimEnd('\r', '\n') + "\r\n";
                    modulesText[_so.PathGetFileNameWithoutExtension(filePath)] = Tuple.Create(moduleText, ModuleProcessing.TypeFromText(moduleText));
                }
            }

            return(modulesText.ToList());
        }