Folders

by Jason on December 20th, 2009
No notes
Syntax: C#
Show lines - Hide lines - Show in textbox - Download
        public static string PathCombine(params string[] pathParts)
        {
            return string.Join(Path.DirectorySeparatorChar.ToString(), pathParts);
        }
 
 
// --------
 
        /// <summary>
        /// Returns the full path to the folder where the plugin's data files are stored.
        /// </summary>
        public string DataFolder(params string[] path)
        {
            return DataFolder(true, path);
        }
 
        /// <summary>
        /// Returns the full path to the folder where the plugin's data files are stored.
        /// </summary>
        /// <param name="path">Any number of optional files/folders to append to the path</param>
        public string DataFolder(bool fallbackToCopy, params string[] path)
        {
            string separator = Path.DirectorySeparatorChar.ToString();
            string target = dataFolder + separator + string.Join(separator, path);
 
            if (!File.Exists(target) && fallbackToCopy)
            {
                string installedPath = InstallFolder(path);
                if (File.Exists(installedPath))
                {
                    Folders.RecursiveCreateDirectory(Path.GetDirectoryName(target));
                    File.Copy(installedPath, target);
                }
            }
 
            return target;
        }
 
 
        /// <summary>
        /// Returns the full path to the folder where the plugin was loaded from.
        /// </summary>
        /// <param name="path">Any number of optional files/folders to append to the path</param>
        public virtual string InstallFolder(params string[] path)
        {
            string separator = Path.DirectorySeparatorChar.ToString();
            return installFolder + separator + string.Join(separator, path);
        }

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS