Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.Test.Common/FileUtils.cs
Aleksei Guzev 1cb0b98148 Fix default test server names file path construction (#941)
FileUtils.TestServerNamesDefaultFileName_get uses '… + @"\\" + …'
construct to build the default path for the test server names file.
While escaping a backslash in a verbatim string is a typo, the
approach was error-prone. Replace string manipulation and environment
variables magic with calls to well-tested library functions.

GetSettingFileContent() displays a message on switching to VS Code
settings when SQL connection instances were configured.
Move the message to the branch for the absent test configuration file.
2020-04-06 08:43:02 -07:00

81 lines
2.6 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
{
public static class FileUtils
{
public static string UserRootFolder
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Environment.GetEnvironmentVariable("USERPROFILE");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return Environment.GetEnvironmentVariable("HOME");
}
else
{
return Environment.GetEnvironmentVariable("HOME");
}
}
}
public static string VsCodeSettingsFileName
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json";
}
else
{
return Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json";
}
}
}
public static string TestServerNamesDefaultFileName
{
get
{
string testServerFileName = "testServerNames.json";
return Path.Combine(TestServerNamesDefaultDirectory, testServerFileName);
}
}
public static string TestServerNamesDefaultDirectory
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}
else
{
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}
}
}
}
}