2017-06-14 12:09:06 -04:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
|
|
|
using NuGet.Configuration;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Configurer
|
|
|
|
{
|
|
|
|
public class FirstTimeUseNoticeSentinel : IFirstTimeUseNoticeSentinel
|
|
|
|
{
|
|
|
|
public static readonly string SENTINEL = $"{Product.Version}.dotnetFirstUseSentinel";
|
|
|
|
|
|
|
|
private readonly IFile _file;
|
2017-06-24 22:59:35 -07:00
|
|
|
private readonly IDirectory _directory;
|
2017-06-14 12:09:06 -04:00
|
|
|
|
2017-06-19 20:52:19 -07:00
|
|
|
private string _dotnetUserProfileFolderPath;
|
2017-06-14 12:09:06 -04:00
|
|
|
|
2017-06-19 20:52:19 -07:00
|
|
|
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
|
2017-06-14 12:09:06 -04:00
|
|
|
|
2018-05-17 12:52:21 -07:00
|
|
|
public FirstTimeUseNoticeSentinel() :
|
2017-06-24 22:59:35 -07:00
|
|
|
this(
|
2017-11-27 10:45:43 -08:00
|
|
|
CliFolderPathCalculator.DotnetUserProfileFolderPath,
|
2017-06-24 22:59:35 -07:00
|
|
|
FileSystemWrapper.Default.File,
|
|
|
|
FileSystemWrapper.Default.Directory)
|
2017-06-14 12:09:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-24 22:59:35 -07:00
|
|
|
internal FirstTimeUseNoticeSentinel(string dotnetUserProfileFolderPath, IFile file, IDirectory directory)
|
2017-06-14 12:09:06 -04:00
|
|
|
{
|
|
|
|
_file = file;
|
2017-06-24 22:59:35 -07:00
|
|
|
_directory = directory;
|
2017-06-19 20:52:19 -07:00
|
|
|
_dotnetUserProfileFolderPath = dotnetUserProfileFolderPath;
|
2017-06-14 12:09:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool Exists()
|
|
|
|
{
|
|
|
|
return _file.Exists(SentinelPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CreateIfNotExists()
|
|
|
|
{
|
|
|
|
if (!Exists())
|
|
|
|
{
|
2017-06-24 22:59:35 -07:00
|
|
|
if (!_directory.Exists(_dotnetUserProfileFolderPath))
|
|
|
|
{
|
|
|
|
_directory.CreateDirectory(_dotnetUserProfileFolderPath);
|
|
|
|
}
|
|
|
|
|
2017-06-14 12:09:06 -04:00
|
|
|
_file.CreateEmptyFile(SentinelPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|