Пример #1
0
        /// <summary>
        /// Convert the given resource filename into a full path (in the given folder) valid for a resource.
        /// All alternate qualifiers are removed and the name is converted to lower case.
        /// The extension is preserved.
        /// </summary>
        public static string GetNormalizedResourcePath(string folder, string resourceFile, ResourceType resourceType)
        {
            var configQualifiers           = ConfigurationQualifiers.Parse(resourceFile);
            var outputFolder               = Path.Combine(folder, resourceType.GetRelativeFolder() + configQualifiers);
            var normalizedResourceFileName = GetNormalizedResourceFileName(resourceFile);

            return(Path.Combine(outputFolder, normalizedResourceFileName));
        }
Пример #2
0
        /// <summary>
        /// Convert the given resource filename into a full path (in the given folder) valid for a resource.
        /// All alternate qualifiers are removed and the name is converted to lower case.
        /// The extension is preserved.
        /// </summary>
        public static string GetNormalizedResourcePath(string folder, string resourceFile, ResourceType resourceType)
        {
            // try the directory name first.
            string directoryName    = Path.GetDirectoryName(resourceFile);
            var    configQualifiers = ConfigurationQualifiers.Parse(directoryName);

            if (string.IsNullOrEmpty(configQualifiers.ToString()))
            {
                configQualifiers = ConfigurationQualifiers.Parse(resourceFile);
            }

            var outputFolder = Path.Combine(folder, resourceType.GetRelativeFolder() + configQualifiers);
            var normalizedResourceFileName = GetNormalizedResourceFileName(resourceFile);

            return(Path.Combine(outputFolder, normalizedResourceFileName));
        }
Пример #3
0
        /// <summary>
        /// Gets the alternate resource data from the given filename and put it in a valid order.
        /// </summary>
        public static ConfigurationQualifiers Parse(string resourceFile)
        {
            var result = new ConfigurationQualifiers();

            if (string.IsNullOrEmpty(resourceFile))
            {
                return(result);
            }
            var name  = GetFileNameWithoutExtension(resourceFile);
            var index = name.IndexOf('-');

            if (index < 0)
            {
                // No alternate resource directory
                return(result);
            }

            name = name.Substring(index + 1).ToLower();
            var parts = name.Split('-').ToList();

            // Detect all allowed qualifiers in order
            string option;
            var    number = 0;

            // Mobile Country Code
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "mcc", null, out number));
            if (option != null)
            {
                result.MobileCountryCode = number;
                parts.Remove(option);
            }

            // Mobile Network Carrier
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "mnc", null, out number));
            if (option != null)
            {
                result.MobileNetworkCarrier = number;
                parts.Remove(option);
            }

            // Country code
            option = parts.FirstOrDefault(x => (x.Length == 2) && CountryCodes.Contains(x));
            if (option != null)
            {
                result.Language = option;
                parts.Remove(option);
            }

            // Region code
            option = parts.FirstOrDefault(x => (x.Length == 3) && (x[0] == 'r') && RegionCodes.Contains(x.Substring(1).ToUpper()));
            if (option != null)
            {
                result.Region = option.Substring(1).ToUpper();
                parts.Remove(option);
            }

            // SmallestWidth
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "sw", "dp", out number));
            if (option != null)
            {
                result.SmallestWidth = number;
                parts.Remove(option);
            }

            // Available Width
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "w", "dp", out number));
            if (option != null)
            {
                result.AvailableWidth = number;
                parts.Remove(option);
            }

            // Available height
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "h", "dp", out number));
            if (option != null)
            {
                result.AvailableHeight = number;
                parts.Remove(option);
            }

            // Screen size
            option = parts.FirstOrDefault(x => ScreenSizeOptions.Contains(x));
            if (option != null)
            {
                result.ScreenSize = ScreenSizeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen aspect
            option = parts.FirstOrDefault(x => ScreenAspectOptions.Contains(x));
            if (option != null)
            {
                result.ScreenAspect = ScreenAspectOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen orientations
            option = parts.FirstOrDefault(x => ScreenOrientationOptions.Contains(x));
            if (option != null)
            {
                result.ScreenOrientation = ScreenOrientationOptions.GetValue(option);
                parts.Remove(option);
            }

            // UI Modes
            option = parts.FirstOrDefault(x => UIModeOptions.Contains(x));
            if (option != null)
            {
                result.UIMode = UIModeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Night mode
            option = parts.FirstOrDefault(x => NightModeOptions.Contains(x));
            if (option != null)
            {
                result.NightMode = NightModeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen pixel density
            option = parts.FirstOrDefault(x => ScreenPixelDensityOptions.Contains(x));
            if (option != null)
            {
                result.ScreenPixelDensity = ScreenPixelDensityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Touch screen type
            option = parts.FirstOrDefault(x => TouchScreenTypeOptions.Contains(x));
            if (option != null)
            {
                result.TouchScreenType = TouchScreenTypeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Keyboard availability
            option = parts.FirstOrDefault(x => KeyboardAvailabilityOptions.Contains(x));
            if (option != null)
            {
                result.KeyboardAvailability = KeyboardAvailabilityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Primary text input method
            option = parts.FirstOrDefault(x => PrimaryTextInputMethodOptions.Contains(x));
            if (option != null)
            {
                result.PrimaryTextInputMethod = PrimaryTextInputMethodOptions.GetValue(option);
                parts.Remove(option);
            }

            // Navigation key availability
            option = parts.FirstOrDefault(x => NavigationKeyAvailabilityOptions.Contains(x));
            if (option != null)
            {
                result.NavigationKeyAvailability = NavigationKeyAvailabilityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Primary non-touch navigation method
            option = parts.FirstOrDefault(x => PrimaryNonTouchNavigationMethodOptions.Contains(x));
            if (option != null)
            {
                result.PrimaryNonTouchNavigationMethod = PrimaryNonTouchNavigationMethodOptions.GetValue(option);
                parts.Remove(option);
            }

            // Platform version
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "v", null, out number));
            if (option != null)
            {
                result.PlatformVersion = number;
                parts.Remove(option);
            }

            return(result);
        }
Пример #4
0
 /// <summary>
 /// Change the filename based on the given qualifiers
 /// </summary>
 private void Save(ConfigurationQualifiers newQualifiers)
 {
     var fileName = FileName;
     var ext = ConfigurationQualifiers.GetExtension(fileName);
     var name = ConfigurationQualifiers.StripQualifiers(fileName, true, false);
     // Update filename
     fileName = name + newQualifiers + ext;
     FileName = fileName;
     // Update cache
     qualifiersFileName = fileName;
     this.qualifiers = newQualifiers;
 }
Пример #5
0
        /// <summary>
        /// Convert the given resource filename into a valid resource name.
        /// All alternate qualifiers are removed, the extension is removed and the name is converted to lower case.
        /// </summary>
        public static string GetNormalizedResourceName(string resourceFile, ResourceType type)
        {
            var normalizeName = ((type < ResourceType.FirstIdType) || (type > ResourceType.LastIdType));

            return(ConfigurationQualifiers.StripQualifiers(resourceFile, true, normalizeName));
        }
Пример #6
0
 /// <summary>
 /// Convert the given resource filename into a filename valid for a resource.
 /// All alternate qualifiers are removed and the name is converted to lower case.
 /// The extension is preserved.
 /// </summary>
 public static string GetNormalizedResourceFileName(string resourceFile)
 {
     return(ConfigurationQualifiers.StripQualifiers(resourceFile, false, true));
 }
Пример #7
0
        /// <summary>
        /// Gets the alternate resource data from the given filename and put it in a valid order.
        /// </summary>
        public static ConfigurationQualifiers Parse(string resourceFile)
        {
            var result = new ConfigurationQualifiers();
            if (string.IsNullOrEmpty(resourceFile))
                return result;
            var name = GetFileNameWithoutExtension(resourceFile);
            var index = name.IndexOf('-');
            if (index < 0)
            {
                // No alternate resource directory
                return result;
            }

            name = name.Substring(index + 1).ToLower();
            var parts = name.Split('-').ToList();

            // Detect all allowed qualifiers in order
            string option;
            var number = 0;

            // Mobile Country Code
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "mcc", null, out number));
            if (option != null)
            {
                result.MobileCountryCode = number;
                parts.Remove(option);
            }

            // Mobile Network Carrier
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "mnc", null, out number));
            if (option != null)
            {
                result.MobileNetworkCarrier = number;
                parts.Remove(option);
            }

            // Country code
            option = parts.FirstOrDefault(x => (x.Length == 2) && CountryCodes.Contains(x));
            if (option != null)
            {
                result.Language = option;
                parts.Remove(option);
            }

            // Region code
            option = parts.FirstOrDefault(x => (x.Length == 3) && (x[0] == 'r') && RegionCodes.Contains(x.Substring(1).ToUpper()));
            if (option != null)
            {
                result.Region = option.Substring(1).ToUpper();
                parts.Remove(option);
            }

            // SmallestWidth
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "sw", "dp", out number));
            if (option != null)
            {
                result.SmallestWidth = number;
                parts.Remove(option);
            }

            // Available Width
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "w", "dp", out number));
            if (option != null)
            {
                result.AvailableWidth = number;
                parts.Remove(option);
            }

            // Available height
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "h", "dp", out number));
            if (option != null)
            {
                result.AvailableHeight = number;
                parts.Remove(option);
            }

            // Screen size
            option = parts.FirstOrDefault(x => ScreenSizeOptions.Contains(x));
            if (option != null)
            {
                result.ScreenSize = ScreenSizeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen aspect
            option = parts.FirstOrDefault(x => ScreenAspectOptions.Contains(x));
            if (option != null)
            {
                result.ScreenAspect = ScreenAspectOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen orientations
            option = parts.FirstOrDefault(x => ScreenOrientationOptions.Contains(x));
            if (option != null)
            {
                result.ScreenOrientation = ScreenOrientationOptions.GetValue(option);
                parts.Remove(option);
            }

            // UI Modes
            option = parts.FirstOrDefault(x => UIModeOptions.Contains(x));
            if (option != null)
            {
                result.UIMode = UIModeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Night mode
            option = parts.FirstOrDefault(x => NightModeOptions.Contains(x));
            if (option != null)
            {
                result.NightMode = NightModeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Screen pixel density
            option = parts.FirstOrDefault(x => ScreenPixelDensityOptions.Contains(x));
            if (option != null)
            {
                result.ScreenPixelDensity = ScreenPixelDensityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Touch screen type
            option = parts.FirstOrDefault(x => TouchScreenTypeOptions.Contains(x));
            if (option != null)
            {
                result.TouchScreenType = TouchScreenTypeOptions.GetValue(option);
                parts.Remove(option);
            }

            // Keyboard availability
            option = parts.FirstOrDefault(x => KeyboardAvailabilityOptions.Contains(x));
            if (option != null)
            {
                result.KeyboardAvailability = KeyboardAvailabilityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Primary text input method
            option = parts.FirstOrDefault(x => PrimaryTextInputMethodOptions.Contains(x));
            if (option != null)
            {
                result.PrimaryTextInputMethod = PrimaryTextInputMethodOptions.GetValue(option);
                parts.Remove(option);
            }

            // Navigation key availability
            option = parts.FirstOrDefault(x => NavigationKeyAvailabilityOptions.Contains(x));
            if (option != null)
            {
                result.NavigationKeyAvailability = NavigationKeyAvailabilityOptions.GetValue(option);
                parts.Remove(option);
            }

            // Primary non-touch navigation method
            option = parts.FirstOrDefault(x => PrimaryNonTouchNavigationMethodOptions.Contains(x));
            if (option != null)
            {
                result.PrimaryNonTouchNavigationMethod = PrimaryNonTouchNavigationMethodOptions.GetValue(option);
                parts.Remove(option);
            }

            // Platform version
            option = parts.FirstOrDefault(x => IsNumberQualifier(x, "v", null, out number));
            if (option != null)
            {
                result.PlatformVersion = number;
                parts.Remove(option);
            }

            return result;
        }