Просмотр исходного кода

update setting of file attributes

Luke Pulverenti 8 лет назад
Родитель
Сommit
1991da85af

+ 44 - 14
Emby.Common.Implementations/IO/ManagedFileSystem.cs

@@ -518,6 +518,49 @@ namespace Emby.Common.Implementations.IO
             }
         }
 
+        public void SetAttributes(string path, bool isHidden, bool isReadOnly)
+        {
+            if (_sharpCifsFileSystem.IsEnabledForPath(path))
+            {
+                _sharpCifsFileSystem.SetAttributes(path, isHidden, isReadOnly);
+                return;
+            }
+
+            var info = GetFileInfo(path);
+
+            if (!info.Exists)
+            {
+                return;
+            }
+
+            if (info.IsReadOnly == isReadOnly && info.IsHidden == isHidden)
+            {
+                return;
+            }
+
+            var attributes = File.GetAttributes(path);
+
+            if (isReadOnly)
+            {
+                attributes = attributes | FileAttributes.ReadOnly;
+            }
+            else
+            {
+                attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
+            }
+
+            if (isHidden)
+            {
+                attributes = attributes | FileAttributes.Hidden;
+            }
+            else
+            {
+                attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
+            }
+
+            File.SetAttributes(path, attributes);
+        }
+
         private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
         {
             return attributes & ~attributesToRemove;
@@ -690,20 +733,7 @@ namespace Emby.Common.Implementations.IO
                 return;
             }
 
-            var fileInfo = GetFileInfo(path);
-
-            if (fileInfo.Exists)
-            {
-                if (fileInfo.IsHidden)
-                {
-                    SetHidden(path, false);
-                }
-                if (fileInfo.IsReadOnly)
-                {
-                    SetReadOnly(path, false);
-                }
-            }
-
+            SetAttributes(path, false, false);
             File.Delete(path);
         }
 

+ 1 - 5
MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs

@@ -218,13 +218,9 @@ namespace MediaBrowser.LocalMetadata.Savers
             {
                 if (file.IsHidden)
                 {
-                    FileSystem.SetHidden(path, false);
                     wasHidden = true;
                 }
-                if (file.IsReadOnly)
-                {
-                    FileSystem.SetReadOnly(path, false);
-                }
+                FileSystem.SetAttributes(path, false, false);
             }
 
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))

+ 2 - 1
MediaBrowser.Model/IO/IFileSystem.cs

@@ -313,7 +313,8 @@ namespace MediaBrowser.Model.IO
         IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
 
         void SetHidden(string path, bool isHidden);
-        void SetReadOnly(string path, bool isHidden);
+        void SetReadOnly(string path, bool readOnly);
+        void SetAttributes(string path, bool isHidden, bool readOnly);
 
         char DirectorySeparatorChar { get; }
 

+ 6 - 21
MediaBrowser.Providers/Manager/ImageSaver.cs

@@ -166,7 +166,7 @@ namespace MediaBrowser.Providers.Manager
             {
                 var currentPath = currentImagePath;
 
-                _logger.Debug("Deleting previous image {0}", currentPath);
+                _logger.Info("Deleting previous image {0}", currentPath);
 
                 _libraryMonitor.ReportFileSystemChangeBeginning(currentPath);
 
@@ -236,7 +236,7 @@ namespace MediaBrowser.Providers.Manager
         /// <returns>Task.</returns>
         private async Task SaveImageToLocation(Stream source, string path, CancellationToken cancellationToken)
         {
-            _logger.Debug("Saving image to {0}", path);
+            _logger.Info("Saving image to {0}", path);
 
             var parentFolder = _fileSystem.GetDirectoryName(path);
 
@@ -249,31 +249,16 @@ namespace MediaBrowser.Providers.Manager
 
                 _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
 
-                // If the file is currently hidden we'll have to remove that or the save will fail
-                var file = _fileSystem.GetFileInfo(path);
+                _fileSystem.SetAttributes(path, false, false);
 
-                // This will fail if the file is hidden
-                if (file.Exists)
+                using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.Asynchronous))
                 {
-                    if (file.IsHidden)
-                    {
-                        _fileSystem.SetHidden(file.FullName, false);
-                    }
-                    if (file.IsReadOnly)
-                    {
-                        _fileSystem.SetReadOnly(path, false);
-                    }
-                }
-
-                using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
-                {
-                    await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken)
-                            .ConfigureAwait(false);
+                    await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
                 }
 
                 if (_config.Configuration.SaveMetadataHidden)
                 {
-                    _fileSystem.SetHidden(file.FullName, true);
+                    _fileSystem.SetHidden(path, true);
                 }
             }
             finally

+ 10 - 9
MediaBrowser.Providers/Omdb/OmdbItemProvider.cs

@@ -72,8 +72,7 @@ namespace MediaBrowser.Providers.Omdb
 
             var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);
 
-            var baseUrl = await OmdbProvider.GetOmdbBaseUrl(cancellationToken).ConfigureAwait(false);
-            var url = baseUrl + "/?plot=full&r=json";
+            var urlQuery = "plot=full&r=json";
             if (type == "episode" && episodeSearchInfo != null)
             {
                 episodeSearchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out imdbId);
@@ -94,23 +93,23 @@ namespace MediaBrowser.Providers.Omdb
             {
                 if (year.HasValue)
                 {
-                    url += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture);
+                    urlQuery += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture);
                 }
 
                 // &s means search and returns a list of results as opposed to t
                 if (isSearch)
                 {
-                    url += "&s=" + WebUtility.UrlEncode(name);
+                    urlQuery += "&s=" + WebUtility.UrlEncode(name);
                 }
                 else
                 {
-                    url += "&t=" + WebUtility.UrlEncode(name);
+                    urlQuery += "&t=" + WebUtility.UrlEncode(name);
                 }
-                url += "&type=" + type;
+                urlQuery += "&type=" + type;
             }
             else
             {
-                url += "&i=" + imdbId;
+                urlQuery += "&i=" + imdbId;
                 isSearch = false;
             }
 
@@ -118,14 +117,16 @@ namespace MediaBrowser.Providers.Omdb
             {
                 if (searchInfo.IndexNumber.HasValue)
                 {
-                    url += string.Format(CultureInfo.InvariantCulture, "&Episode={0}", searchInfo.IndexNumber);
+                    urlQuery += string.Format(CultureInfo.InvariantCulture, "&Episode={0}", searchInfo.IndexNumber);
                 }
                 if (searchInfo.ParentIndexNumber.HasValue)
                 {
-                    url += string.Format(CultureInfo.InvariantCulture, "&Season={0}", searchInfo.ParentIndexNumber);
+                    urlQuery += string.Format(CultureInfo.InvariantCulture, "&Season={0}", searchInfo.ParentIndexNumber);
                 }
             }
 
+            var url = await OmdbProvider.GetOmdbUrl(urlQuery, cancellationToken).ConfigureAwait(false);
+
             using (var stream = await OmdbProvider.GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
             {
                 var resultList = new List<SearchResult>();

+ 11 - 6
MediaBrowser.Providers/Omdb/OmdbProvider.cs

@@ -265,9 +265,16 @@ namespace MediaBrowser.Providers.Omdb
             return false;
         }
 
-        public static async Task<string> GetOmdbBaseUrl(CancellationToken cancellationToken)
+        public static async Task<string> GetOmdbUrl(string query, CancellationToken cancellationToken)
         {
-            return "https://www.omdbapi.com";
+            var url = "https://www.omdbapi.com?apikey=fe53f97e";
+
+            if (!string.IsNullOrWhiteSpace(query))
+            {
+                url += "&" + query;
+            }
+
+            return url;
         }
 
         private async Task<string> EnsureItemInfo(string imdbId, CancellationToken cancellationToken)
@@ -292,8 +299,7 @@ namespace MediaBrowser.Providers.Omdb
                 }
             }
 
-            var baseUrl = await GetOmdbBaseUrl(cancellationToken).ConfigureAwait(false);
-            var url = string.Format(baseUrl + "/?i={0}&plot=full&tomatoes=true&r=json", imdbParam);
+            var url = await GetOmdbUrl(string.Format("i={0}&plot=full&tomatoes=true&r=json", imdbParam), cancellationToken).ConfigureAwait(false);
 
             using (var stream = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
             {
@@ -327,8 +333,7 @@ namespace MediaBrowser.Providers.Omdb
                 }
             }
 
-            var baseUrl = await GetOmdbBaseUrl(cancellationToken).ConfigureAwait(false);
-            var url = string.Format(baseUrl + "/?i={0}&season={1}&detail=full", imdbParam, seasonId);
+            var url = await GetOmdbUrl(string.Format("i={0}&season={1}&detail=full", imdbParam, seasonId), cancellationToken).ConfigureAwait(false);
 
             using (var stream = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
             {

+ 1 - 6
MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs

@@ -220,14 +220,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
             {
                 if (file.IsHidden)
                 {
-                    FileSystem.SetHidden(path, false);
-
                     wasHidden = true;
                 }
-                if (file.IsReadOnly)
-                {
-                    FileSystem.SetReadOnly(path, false);
-                }
+                FileSystem.SetAttributes(path, false, false);
             }
 
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))