예제 #1
0
        /// <summary>
        /// Gets the absolute path of a file if it is accessible.
        /// </summary>
        /// <param name="relativePath">The relative path to the file. If it begins with a path token, the token will be resolved as well.</param>
        /// <param name="result">The variable which will hold the absolute path.</param>
        /// <returns><c>true</c> if the file is accessible.</returns>
        public static bool TryResolvePath(string relativePath, out string result)
        {
            result = null;
            try
            {
                // If the path contains a path token, resolve the path relative to it
                if (PathToken.IsInPath(relativePath))
                {
                    return(PathToken.TryResolvePath(relativePath, out result));
                }

                // Resolve the path relative to the game root
                string simplifiedPath;
                if (!PathUtil.SimplifyRelativePath(relativePath, out simplifiedPath))
                {
                    return(false);
                }
                result = Path.Combine(Config.Current.GameRoot, simplifiedPath);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
        public override string IO_OS_GetTempFilename()
        {
            var dir = Path.Combine(Path.GetTempPath(), TempFileDirName);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            var fileName = Path.Combine(dir, Path.GetRandomFileName());

            File.Create(fileName).Dispose();
            _tempFiles.AddFile(fileName, false);
            return(PathToken.Generate(fileName));
        }