public static AXmlResource[] ReadAllFiles(string aProjPath, string sourceLan, out AXmlResource sourceFile)
        {
            DirectoryInfo aProjDir = new DirectoryInfo(Path.Combine(aProjPath, AXmlHelper.AXML_PATH));

            FileInfo[] aFiles = aProjDir.GetFiles("strings.xml", SearchOption.AllDirectories);

            List <AXmlResource> aResources = new List <AXmlResource>();

            sourceFile = null;

            foreach (FileInfo aFile in aFiles)
            {
                AXmlResource resource = AXmlHelper.ReadAXml(aFile.FullName);
                if (resource != null)
                {
                    Console.WriteLine($"{aFile.Directory.Name}/{aFile.Name} successfully read");
                }
                else
                {
                    Console.WriteLine($"Error reading file {aFile.Directory.Name}/{aFile.Name}");
                }

                if (resource == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(sourceLan))
                {
                    if (String.Compare(resource.Language, sourceLan, true) == 0)
                    {
                        sourceFile = resource;
                    }
                }
                else
                {
                    if (aFile.Directory.Name == "values")
                    {
                        sourceFile = resource;
                    }
                }

                aResources.Add(resource);
            }

            return(aResources.ToArray());
        }
示例#2
0
        public void Extract()
        {
            AXmlResource sourceRes;

            AXmlResource[] projResources = AXmlHelper.ReadAllFiles(this.Options.ProjectPath, this.Options.SourceLanguage, out sourceRes);

            if (sourceRes == null)
            {
                throw new Exception("Default resource not found");
            }

            for (int i = 0; i < projResources.Length; i++)
            {
                AXmlResource projResource = projResources[i];
                Console.WriteLine($"Processing {projResource.Language}");
                var targetResource = new AXmlResource()
                {
                    FolderParts = projResource.FolderParts
                };
                foreach (var resString in sourceRes)
                {
                    if (!projResource.Any(r => r.Name == resString.Name))
                    {
                        targetResource.Add(resString.Clone());
                    }
                }

                if (targetResource.Count == 0)
                {
                    continue;
                }

                Console.WriteLine($"Saving {projResource.Language}");

                AXmlHelper.SaveAXml(targetResource, Path.Combine(this.Options.TargetPath, String.Join("-", targetResource.FolderParts), "strings.xml"));
            }

            Console.WriteLine("Saving initial file (source.xml)");
            AXmlHelper.SaveAXml(sourceRes, Path.Combine(this.Options.TargetPath, "source.xml"));
        }