GetOptionValue() private method

private GetOptionValue ( string name ) : string
name string
return string
コード例 #1
0
        private static string GetConfigurationFileLocation(Request request)
        {
            var filePath = request.GetOptionValue("ConfigFile");
            if (String.IsNullOrEmpty(filePath))
            {
                //otherwise, use %APPDATA%/EXE/Smart.Config
                filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EXE", "Smart.config");
            }

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));

            // TODO: this can fail if we don't have permissions - need to verify if OneGet would display a good error message
            using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                if (fs.Length == 0)
                {
                    using (var sw = new StreamWriter(fs))
                    {
                        sw.WriteLine(DefaultConfig);
                        sw.Flush();
                    }
                }
                fs.Close();
            }

            return filePath;
        }