示例#1
0
        string GetRootAndroid(RootLocation root)
        {
            switch (root)
            {
            case RootLocation.AllUserConfig:
            case RootLocation.AllUsersData:
            {
                string path = FileSystem.Combine(ProgramDirectory, ".AllUsers");
                Directory.CreateDirectory(path);
                return(path);
            }

            case RootLocation.LocalUserConfig:
            case RootLocation.LocalUserData:
            case RootLocation.RoamingUserConfig:
            case RootLocation.RoamingUserData:
            {
                string path = FileSystem.Combine(ProgramDirectory, ".User_" + Environment.UserName);
                Directory.CreateDirectory(path);
                return(path);
            }

            case RootLocation.Program: return(ProgramDirectory);

            default: throw new ArgumentOutOfRangeException(string.Format("RootLocation {0} unknown", root));
            }
        }
示例#2
0
        string GetRootWindows(RootLocation root)
        {
            switch (root)
            {
            case RootLocation.AllUserConfig:
            case RootLocation.AllUsersData: return(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));

            case RootLocation.LocalUserConfig:
            case RootLocation.LocalUserData: return(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

            case RootLocation.RoamingUserConfig:
            case RootLocation.RoamingUserData: return(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

            case RootLocation.Program: return(ProgramDirectory);

            default: throw new ArgumentOutOfRangeException(string.Format("RootLocation {0} unknown", root));
            }
        }
示例#3
0
        /// <summary>Initializes a new instance of the <see cref="FileLocation" /> class.</summary>
        /// <param name="root">The root folder. Is unset, this will be set to roaming user.</param>
        /// <param name="companyName">Name of the company. If unset, this will be set to the assemblies company name.</param>
        /// <param name="subFolder">The sub folder.</param>
        /// <param name="fileName">Name of the file. If unset, this will be set to the assemblies product name.</param>
        /// <param name="extension">The extension.</param>
        public FileLocation(RootLocation root = RootLocation.Program, string companyName = null, string subFolder = null, string fileName = null, string extension = null)
        {
            Root      = root;
            SubFolder = subFolder;
            Extension = extension;
            switch (Platform.Type)
            {
            case PlatformType.BSD:
            case PlatformType.Linux:
            case PlatformType.UnknownUnix:
                FileName = fileName ?? AssemblyVersionInfo.Program.Product.ToLower().ReplaceInvalidChars(ASCII.Strings.Letters + ASCII.Strings.Digits, "-");
                break;

            default:
                CompanyName = companyName ?? AssemblyVersionInfo.Program.Company.ReplaceChars(Path.GetInvalidPathChars(), "_");
                FileName    = fileName ?? AssemblyVersionInfo.Program.Product.ReplaceChars(Path.GetInvalidFileNameChars(), "_");
                break;
            }
        }
        /// <summary>
        /// Creates a new resource that is relative to this resource based on the
        /// supplied <paramref name="resourceName"/>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// This method can accept either a fully qualified resource name or a
        /// relative resource name as it's parameter.
        /// </p>
        /// <p>
        /// A fully qualified resource is one that has a protocol prefix and
        /// all elements of the resource name. All other resources are treated
        /// as relative to this resource, and the following rules are used to
        /// locate a relative resource:
        /// </p>
        /// <list type="bullet">
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with <c>'..'</c>,
        ///     the current resource path is navigated backwards before the
        ///     <paramref name="resourceName"/> is concatenated to the current
        ///     <see cref="Spring.Core.IO.AbstractResource.ResourcePath"/> of
        ///     this resource.
        ///     </item>
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with '/', the
        ///     current resource path is ignored and a new resource name is
        ///     appended to the
        ///     <see cref="Spring.Core.IO.AbstractResource.RootLocation"/> of
        ///     this resource.
        ///     </item>
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with '.' or a
        ///     letter, a new path is appended to the current
        ///     <see cref="Spring.Core.IO.AbstractResource.ResourcePath"/> of
        ///     this resource.
        ///     </item>
        /// </list>
        /// </remarks>
        /// <param name="resourceName">
        /// The name of the resource to create.
        /// </param>
        /// <returns>The relative resource.</returns>
        /// <exception cref="System.UriFormatException">
        /// If the process of resolving the relative resource yielded an
        /// invalid URI.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// If this resource does not support the resolution of relative
        /// resources (as determined by the value of the
        /// <see cref="Spring.Core.IO.AbstractResource.SupportsRelativeResources"/>
        /// property).
        /// </exception>
        /// <seealso cref="Spring.Core.IO.AbstractResource.ResourcePath"/>
        public virtual IResource CreateRelative(string resourceName)
        {
            AssertUtils.ArgumentNotNull(resourceName, "relativePath");

            // try to create fully qualified resource...
            IResourceLoader loader = GetResourceLoader();

            if (ConfigurableResourceLoader.HasProtocol(resourceName))
            {
                IResource resource = loader.GetResource(resourceName);
                if (resource != null)
                {
                    return(resource);
                }
            }
            if (!SupportsRelativeResources)
            {
                throw new NotSupportedException(GetType().Name +
                                                " does not support relative resources. Please use fully qualified resource name.");
            }

            StringBuilder fullResourceName = new StringBuilder(256);

            if (Protocol != null && Protocol != String.Empty)
            {
                fullResourceName.Append(Protocol).Append(ConfigurableResourceLoader.ProtocolSeparator);
            }

            if (!IsRelativeResource(resourceName))
            {
                fullResourceName.Append(resourceName);
            }
            else
            {
                string targetResource;
                string resourcePath;
                int    n = resourceName.LastIndexOfAny(new char[] { '/', '\\' });
                if (n >= 0)
                {
                    targetResource = resourceName.Substring(n + 1);
                    resourcePath   = CalculateResourcePath(resourceName.Substring(0, n + 1));
                }
                else // only resource name is specified, so current path should be used
                {
                    targetResource = resourceName;
                    resourcePath   = ResourcePath;
                }

                fullResourceName.Append(RootLocation.TrimEnd('\\', '/'));
                if (resourcePath != null && resourcePath != String.Empty)
                {
                    fullResourceName.Append('/').Append(resourcePath);
                }
                fullResourceName.Append('/').Append(targetResource);
            }

            string resultResourceName = fullResourceName.ToString();

            if (!ConfigurableResourceLoader.HasProtocol(resultResourceName))
            {
                // give derived resource classes a chance to create an instance on their own
                IResource resultResource = CreateResourceInstance(resultResourceName);
                if (resultResource != null)
                {
                    return(resultResource);
                }
            }

            // create resource instance using default loader
            return(loader.GetResource(resultResourceName));
        }