Bloom.CollectionChoosing.OpenCreateCloneControl.CheckForBeingInDropboxFolder C# (CSharp) Method

CheckForBeingInDropboxFolder() public static method

This method checks 'path' for being in a Dropbox folder. If so, it displays a warning message.
public static CheckForBeingInDropboxFolder ( string path ) : void
path string
return void
        public static void CheckForBeingInDropboxFolder(string path)
        {
            if (string.IsNullOrEmpty(path)) return;

            try
            {
                if (_dropboxFolders == null)
                {
                    _dropboxFolders = new List<string>();
                    string dropboxInfoFile;
                    // On Windows, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns
                    // the path of the user's AppData/Roaming subdirectory.  I know the name looks like it should
                    // return the AppData directory itself, but it returns the Roaming subdirectory (although
                    // there seems to be some confusion about this on stackoverflow.)  MSDN has this to say to
                    // describe this enumeration value:
                    //    The directory that serves as a common repository for application-specific data for the
                    //    current roaming user.
                    // My tests on Windows 7/.Net 4.0 empirically show the return value looks something like
                    //    C:\Users\username\AppData\Roaming
                    // On Linux/Mono 3, the return value looks something like
                    //    /home/username/.config
                    // but Dropbox places its .dropbox folder in the user's home directory so we need to strip
                    // one directory level from that return value.
                    var baseFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    if (SIL.PlatformUtilities.Platform.IsWindows)
                        dropboxInfoFile = Path.Combine(baseFolder, @"Dropbox\info.json");
                    else
                        dropboxInfoFile = Path.Combine(Path.GetDirectoryName(baseFolder), @".dropbox/info.json");

                    //on my windows 10 box, the file we want is in AppData\Local\Dropbox
                    if (!RobustFile.Exists(dropboxInfoFile))
                    {
                        baseFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        if (SIL.PlatformUtilities.Platform.IsWindows)
                            dropboxInfoFile = Path.Combine(baseFolder, @"Dropbox\info.json");
                        else
                            dropboxInfoFile = Path.Combine(Path.GetDirectoryName(baseFolder), @".dropbox/info.json");
                        if (!RobustFile.Exists(dropboxInfoFile))
                            return; // User appears to not have Dropbox installed
                    }

                    var info = RobustFile.ReadAllText(dropboxInfoFile);
                    var matches = Regex.Matches(info, @"{""path"": ""([^""]+)"",");
                    foreach (Match match in matches)
                    {
                        var folder = match.Groups[1].Value;
                        if (SIL.PlatformUtilities.Platform.IsWindows)
                        {
                            folder = folder.Replace("\\\\", "\\");
                            folder = folder.ToLowerInvariant();
                        }
                        _dropboxFolders.Add(folder + Path.DirectorySeparatorChar);
                    }
                }

                if (_dropboxFolders.Count == 0)
                    return; // User appears to not have Dropbox installed

                if (SIL.PlatformUtilities.Platform.IsWindows)
                    path = path.ToLowerInvariant(); // We do a case-insensitive compare on Windows.

                foreach (var folder in _dropboxFolders)
                {
                    if (path.StartsWith(folder))
                    {
                        var msg = L10NSharp.LocalizationManager.GetString("OpenCreateCloneControl.InDropboxMessage",
                            "Bloom detected that this collection is located in your Dropbox folder. This can cause problems as Dropbox sometimes locks Bloom out of its own files. If you have problems, we recommend that you move your collection somewhere else or disable Dropbox while using Bloom.",
                            "");
                        SIL.Reporting.ErrorReport.NotifyUserOfProblem(msg);
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                // To help fix BL-1246, we enable this:
                SIL.Reporting.ErrorReport.NotifyUserOfProblem(e,
                    "For some reason Bloom could not check your Dropbox settings. This should not cause you any problems, but please report it so we can fix it.");
                SIL.Reporting.Logger.WriteEvent("*** In CheckForBeingInDropboxFolder(), got "+e.Message+Environment.NewLine+e.StackTrace);
                Debug.Fail(e.Message);
            }
        }