void FindAndAddSatellites(string filename, string parent_copy_local)
        {
            if (!FindSatellites)
            {
                return;
            }

            string basepath = Path.GetDirectoryName(filename);
            string resource = String.Format("{0}{1}{2}",
                                            Path.GetFileNameWithoutExtension(filename),
                                            ".resources",
                                            Path.GetExtension(filename));

            string dir_sep = Path.DirectorySeparatorChar.ToString();

            foreach (string dir in Directory.GetDirectories(basepath))
            {
                string culture = Path.GetFileName(dir);
                if (!CultureNamesTable.ContainsKey(culture))
                {
                    continue;
                }

                string res_path = Path.Combine(dir, resource);
                if (File.Exists(res_path))
                {
                    ITaskItem item = new TaskItem(res_path);
                    SetCopyLocal(item, parent_copy_local);
                    item.SetMetadata("DestinationSubdirectory", culture + dir_sep);
                    tempSatelliteFiles.AddUniqueFile(item);
                }
            }
        }
Example #2
0
        //Given a filename like foo.it.resx, splits it into - foo, it, resx
        //Returns true only if a valid culture is found
        //Note: hand-written as this can get called lotsa times
        internal static bool TrySplitResourceName(string fname, out string only_filename, out string culture, out string extn)
        {
            only_filename = culture = extn = null;

            int last_dot    = -1;
            int culture_dot = -1;
            int i           = fname.Length - 1;

            while (i >= 0)
            {
                if (fname [i] == '.')
                {
                    last_dot = i;
                    break;
                }
                i--;
            }
            if (i < 0)
            {
                return(false);
            }

            i--;
            while (i >= 0)
            {
                if (fname [i] == '.')
                {
                    culture_dot = i;
                    break;
                }
                i--;
            }
            if (culture_dot < 0)
            {
                return(false);
            }

            culture = fname.Substring(culture_dot + 1, last_dot - culture_dot - 1);
            if (!CultureNamesTable.ContainsKey(culture))
            {
                culture = null;
                return(false);
            }

            only_filename = fname.Substring(0, culture_dot);
            extn          = fname.Substring(last_dot + 1);
            return(true);
        }
Example #3
0
        //Given a filename like foo.it.resx, get 'it', if its
        //a valid culture
        //Note: hand-written as this can get called lotsa times
        //Note: code duplicated in prj2make/Utils.cs as TrySplitResourceName
        string GetCulture(string fname)
        {
            int last_dot    = -1;
            int culture_dot = -1;
            int i           = fname.Length - 1;

            while (i >= 0)
            {
                if (fname [i] == '.')
                {
                    last_dot = i;
                    break;
                }
                i--;
            }
            if (i < 0)
            {
                return(null);
            }

            i--;
            while (i >= 0)
            {
                if (fname [i] == '.')
                {
                    culture_dot = i;
                    break;
                }
                i--;
            }
            if (culture_dot < 0)
            {
                return(null);
            }

            string culture = fname.Substring(culture_dot + 1, last_dot - culture_dot - 1);

            if (!CultureNamesTable.ContainsKey(culture))
            {
                return(null);
            }

            return(culture);
        }