/// <summary>
        /// Creates a filter for a special folder
        /// </summary>
        /// <param name="specialFolder">Special folder</param>
        /// <returns>Special folder filter</returns>
        private static string CreateSpecialFolderFilter(Environment.SpecialFolder specialFolder)
        {
            string folderPath = Environment.GetFolderPath(specialFolder);

            if (!string.IsNullOrEmpty(folderPath))
            {
                // Note that this also replaces alternate directory separators with regular ones
                string filter = FilterGroups.CreateWildcardFilter(folderPath);

                // Duplicati matches filters against folder paths exactly.
                // Meaning a filter for 'C:\Windows' won't match 'C:\Windows\'.
                // So this makes sure special folder's filter's have a trailing directory separator.
                // (Alternatively, this could append '*' to all folder filters.)
                return(Utility.AppendDirSeparator(filter));
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
 public TempFolder(string folder)
 {
     m_protect = false;
     m_folder  = Utility.AppendDirSeparator(folder);
     System.IO.Directory.CreateDirectory(m_folder);
 }
        /// <summary>
        /// Creates Windows filters
        /// </summary>
        /// <param name="group">The groups to create the filters for</param>
        /// <returns>Windows filters</returns>
        private static IEnumerable <string> CreateWindowsFilters(FilterGroup group)
        {
            if (group.HasFlag(FilterGroup.SystemFiles))
            {
                yield return(FilterGroups.CreateWildcardFilter(@"*/I386*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Internet Explorer/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Microsoft*/RecoveryStore*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Microsoft*/Windows/*.edb"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Microsoft*/Windows/*.log"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Microsoft*/Windows/Cookies*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/MSOCache*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/NTUSER*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/RECYCLER/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*UsrClass.dat*"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/hiberfil.sys"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/pagefile.sys"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/swapfile.sys"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/System Volume Information/"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/Windows/Installer*"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/Windows/Temp*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/ntuser.dat*"));

                foreach (var s in GetWindowsRegistryFilters() ?? new string[0])
                {
                    // If this path refers to the root of a drive, then prepend it with "?:" since that's how Duplicati's root path matching works.
                    if (s.StartsWith(@"\", StringComparison.Ordinal) || s.StartsWith("/", StringComparison.Ordinal))
                    {
                        yield return("?:" + s);
                    }
                    else
                    {
                        yield return(s);
                    }
                }
            }

            if (group.HasFlag(FilterGroup.OperatingSystem))
            {
                yield return(FilterGroups.CreateWildcardFilter(@"?:/Config.Msi*")); // https://github.com/duplicati/duplicati/issues/2886

                yield return(FilterGroups.CreateWildcardFilter(@"*/Recent/"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/autoexec.bat"));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.System));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.SystemX86));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.Windows));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.Recent));

                var windir = FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.Windows);
                if (!string.IsNullOrWhiteSpace(windir))
                {
                    yield return(windir);

                    // Also exclude "C:\Windows.old\"
                    yield return(Utility.AppendDirSeparator(windir.TrimEnd('\\', '/') + ".old"));
                }
            }

            if (group.HasFlag(FilterGroup.CacheFiles))
            {
                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/AMD/DxCache/")); // Appears to be a shader cache folder for AMD video card drivers

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Apple Computer/Mobile Sync/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Comms/UnistoreDB/"));            // Looks like storage about music / pictures for universal store apps

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/ElevatedDiagnostics/"));         // Seems to be used by sfc tool and Windows troubleshooting

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/VSCommon/*SQM*"));     // SQM appears to be 'service quality management', and it looks like these files report things about Visual Studio installation: https://stackoverflow.com/questions/23050561/what-permissions-policies-are-needed-to-support-loaduserprofile-true-for-new-app

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/Windows/Explorer/"));  // Stores icon and thumbnail caches

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/Windows/INetCache/")); //

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/Windows/UPPS/"));      // Not sure what this one is, but seems to be a common one to fail to backup: http://support.wdc.com/knowledgebase/answer.aspx?ID=17969&lang=en

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/Windows/WebCache*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Microsoft/Windows Store/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Packages/")); // https://superuser.com/questions/490925/explain-windows-8-windows-store-appdata-packages-and-what-to-backup

                yield return(FilterGroups.CreateWildcardFilter(@"*/Application Data/Apple Computer/Mobile Sync/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Application Data/Application Data*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Dropbox/Dropbox.exe.log")); // Dropbox log file, which may be kept open by Dropbox while it is running

                yield return(FilterGroups.CreateWildcardFilter(@"*/Dropbox/QuitReports/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Google/Chrome/User Data/Default/Cookies"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Google/Chrome/User Data/Default/Cookies-journal"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Local Settings/History/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/OneDrive/.849C9593-D756-4E56-8D6E-42412F2A707B")); // This looks like a hidden cache file for the OneDrive service: https://onedrive.uservoice.com/forums/262982-onedrive/suggestions/10059663-get-rid-of-undeleteable-849c9593-d756-4e56-8d6e

                yield return(FilterGroups.CreateWildcardFilter(@"*/Safari/Library/Caches/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Temporary Internet Files/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Thumbs.db"));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.History));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.InternetCache));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.Cookies));
            }

            if (group.HasFlag(FilterGroup.TemporaryFiles))
            {
                yield return(FilterGroups.CreateWildcardFilter(@"*/$RECYCLE.BIN/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*.tmp"));

                yield return(FilterGroups.CreateWildcardFilter(@"*.tmp/"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Local/Temp*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/AppData/Temp*"));

                yield return(FilterGroups.CreateWildcardFilter(@"*/Local Settings/Temp*"));

                yield return(FilterGroups.CreateWildcardFilter(@"?:/Windows/Temp*"));
            }

            if (group.HasFlag(FilterGroup.Applications))
            {
                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.ProgramFiles));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.ProgramFilesX86));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.AdminTools));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.CommonProgramFiles));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.CommonProgramFilesX86));

                yield return(FilterGroups.CreateSpecialFolderFilter(Environment.SpecialFolder.CommonAdminTools));
            }
        }