Skip to content
Permalink
Browse files

Extra typecasts added, and '+' replaced with '|'

  • Loading branch information...
owlsroost committed Mar 20, 2019
1 parent 3a2a80b commit 4f5af9910d72bed33ed8e0e094dabfb78dbdc972
Showing with 79 additions and 81 deletions.
  1. +5 −7 mediaportal/Core/Util/NativeFileSystemOperations.cs
  2. +74 −74 mediaportal/Core/Util/VirtualDirectory.cs
@@ -187,14 +187,12 @@ public static FileInformation[] GetFileInformation(string directory, bool includ
if (includeSystemAndHidden ||
(findData.dwFileAttributes & ((uint)FileAttributes.Hidden | (uint)FileAttributes.System)) == 0)
{
FileInformation fileInfo = new FileInformation();
long ftCreationTime = (((long)findData.ftCreationTime.dwHighDateTime) << 32) +
findData.ftCreationTime.dwLowDateTime;
long ftLastWriteTime = (((long)findData.ftLastWriteTime.dwHighDateTime) << 32) +
findData.ftLastWriteTime.dwLowDateTime;
FileInformation fileInfo = new FileInformation();
long ftCreationTime = (((long)findData.ftCreationTime.dwHighDateTime) << 32) | (uint)findData.ftCreationTime.dwLowDateTime;
long ftLastWriteTime = (((long)findData.ftLastWriteTime.dwHighDateTime) << 32) | (uint)findData.ftLastWriteTime.dwLowDateTime;
fileInfo.Name = Path.Combine(directory, findData.cFileName);
if (prefix == UNCPrefix) fileInfo.Name = @"\\" + fileInfo.Name;
fileInfo.Length = (((long)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
if (prefix == UNCPrefix) fileInfo.Name = @"\\" + fileInfo.Name;
fileInfo.Length = (((long)findData.nFileSizeHigh) << 32) | (uint)findData.nFileSizeLow;
fileInfo.CreationTime = DateTime.FromFileTimeUtc(ftCreationTime);
fileInfo.ModificationTime = DateTime.FromFileTimeUtc(ftLastWriteTime);
fi.Add(fileInfo);
@@ -56,8 +56,8 @@ public class VirtualDirectory
private bool showFilesWithoutExtension;

private List<GUIListItem> _cachedItems = new List<GUIListItem>();
private string _cachedDir = null;
private List<string> ignoredItems = new List<string>();
private string _cachedDir = null;
private List<string> ignoredItems = new List<string>();
private List<string> detectedItems = new List<string>();
internal static List<string> detectedItemsPath = new List<string>();

@@ -1588,14 +1588,14 @@ public List<GUIListItem> GetRootExt()

Log.Debug("GetRootExt(): ShareOffline : '{0}' doesn't exists or offline, enable WOL feature for permanent loading", share.Path);
Log.Debug("GetRootExt(): ShareOffline : '{0}' can be refreshed from context menu in share view mode", share.Path);
}
else
{
items.Add(item);
}
}
}

}
else
{
items.Add(item);
}
}
}

// add removable drives with media
string[] drives = Environment.GetLogicalDrives();
foreach (string drive in drives)
@@ -1638,70 +1638,70 @@ public List<GUIListItem> GetRootExt()
}

return items;
}

}

private void HandleLocalFilesInDir(string aDirectory, ref List<GUIListItem> aItemsList, bool aHasRedbookDetails, bool loadHidden)
{
{
this.HandleLocalFilesInDir(aDirectory, ref aItemsList, aHasRedbookDetails, false, loadHidden);
}

private void HandleLocalFilesInDir(string aDirectory, ref List<GUIListItem> aItemsList, bool aHasRedbookDetails,
bool useCache, bool loadHidden)
{
//This function is only used inside GetDirectoryUnProtectedExt. GetDirectoryUnProtectedExt is
//mainly used for internal loading. That means it isn't called when the user explicitly enters a
//directory, but just when MP means it needs to query a directory. The bad thing is that the code
//has grown much over the time and these function is called way too often, which can result in very bad performance
//Anyway it isn't really a good idea to always reload a directory completely if it isn't really neccessary.
//This change is not meant as the perfect solution, but anything other whould more or less mean a complete remake.
//The main purpose of this tweak is to boost the performance when starting/stopping playback, because atm
//start playback triggers a complete reload 2-3 times and stop playback another 1-2 times.

if (useCache && !string.IsNullOrEmpty(_cachedDir) && aDirectory == _cachedDir)
{
aItemsList.AddRange(_cachedItems);
return;
}

_cachedItems.Clear();
_cachedDir = null;

try
{
IntPtr handle = new IntPtr(-1);
Win32API.WIN32_FIND_DATA fd = new Win32API.WIN32_FIND_DATA();
fd.cFileName = new String(' ', 256);
fd.cAlternate = new String(' ', 14);
// http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
bool available = UNCTools.UNCFileFolderExists(aDirectory);
if (available)
{
handle = Win32API.FindFirstFile(aDirectory + @"\*.*", out fd);
}

int count = 0;
do
{
try
{
count++;

if (fd.cFileName == "." || fd.cFileName == "..")
{
continue;
}

GUIListItem item;
}

private void HandleLocalFilesInDir(string aDirectory, ref List<GUIListItem> aItemsList, bool aHasRedbookDetails,
bool useCache, bool loadHidden)
{
//This function is only used inside GetDirectoryUnProtectedExt. GetDirectoryUnProtectedExt is
//mainly used for internal loading. That means it isn't called when the user explicitly enters a
//directory, but just when MP means it needs to query a directory. The bad thing is that the code
//has grown much over the time and these function is called way too often, which can result in very bad performance
//Anyway it isn't really a good idea to always reload a directory completely if it isn't really neccessary.
//This change is not meant as the perfect solution, but anything other whould more or less mean a complete remake.
//The main purpose of this tweak is to boost the performance when starting/stopping playback, because atm
//start playback triggers a complete reload 2-3 times and stop playback another 1-2 times.

if (useCache && !string.IsNullOrEmpty(_cachedDir) && aDirectory == _cachedDir)
{
aItemsList.AddRange(_cachedItems);
return;
}

_cachedItems.Clear();
_cachedDir = null;

try
{
IntPtr handle = new IntPtr(-1);
Win32API.WIN32_FIND_DATA fd = new Win32API.WIN32_FIND_DATA();
fd.cFileName = new String(' ', 256);
fd.cAlternate = new String(' ', 14);
// http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
bool available = UNCTools.UNCFileFolderExists(aDirectory);
if (available)
{
handle = Win32API.FindFirstFile(aDirectory + @"\*.*", out fd);
}

int count = 0;
do
{
try
{
count++;

if (fd.cFileName == "." || fd.cFileName == "..")
{
continue;
}

GUIListItem item;
string FileName = aDirectory + @"\" + fd.cFileName;

long ftCreationTime = (((long)fd.ftCreationTime.dwHighDateTime) << 32) + fd.ftCreationTime.dwLowDateTime;
long ftLastWriteTime = (((long)fd.ftLastWriteTime.dwHighDateTime) << 32) + fd.ftLastWriteTime.dwLowDateTime;
long ftCreationTime = (((long)fd.ftCreationTime.dwHighDateTime) << 32) | (uint)fd.ftCreationTime.dwLowDateTime;
long ftLastWriteTime = (((long)fd.ftLastWriteTime.dwHighDateTime) << 32) | (uint)fd.ftLastWriteTime.dwLowDateTime;

FileInformation fi = new FileInformation();

fi.CreationTime = DateTime.FromFileTimeUtc(ftCreationTime);
fi.ModificationTime = DateTime.FromFileTimeUtc(ftLastWriteTime);
fi.Length = (((long)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
fi.Length = (((long)fd.nFileSizeHigh) << 32) | (uint)fd.nFileSizeLow;

if ((fd.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
{
@@ -1793,15 +1793,15 @@ private void HandleLocalFilesInDir(string aDirectory, ref List<GUIListItem> aIte
Win32API.FindClose(handle);

_cachedDir = aDirectory;
}
catch (Exception ex)
{
Log.Error("VirtualDirectory: Could not browse folder {0}: {1}", aDirectory, ex.Message);

_cachedItems.Clear();
_cachedDir = null;
}
}
}
catch (Exception ex)
{
Log.Error("VirtualDirectory: Could not browse folder {0}: {1}", aDirectory, ex.Message);

_cachedItems.Clear();
_cachedDir = null;
}
}


///// <summary>

0 comments on commit 4f5af99

Please sign in to comment.
You can’t perform that action at this time.