Skip to content

Commit

Permalink
fix possible race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Jul 2, 2022
1 parent fb294c4 commit 40565e8
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/Misc/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,41 +1276,47 @@ public void LoadDiskFolder(string path)
}
}

static object LoadFolderLockObject = new object();

public void LoadFolder()
{
if (!App.AutoLoadFolder || Control.ModifierKeys.HasFlag(Keys.Shift))
return;

Thread.Sleep(1000);
string path = GetPropertyString("path");

if (!File.Exists(path) || GetPropertyInt("playlist-count") != 1)
return;
lock (LoadFolderLockObject)
{
string path = GetPropertyString("path");

if (!File.Exists(path) || GetPropertyInt("playlist-count") != 1)
return;

string dir = Environment.CurrentDirectory;
string dir = Environment.CurrentDirectory;

if (path.Contains(":/") && !path.Contains("://"))
path = path.Replace("/", "\\");
if (path.Contains(":/") && !path.Contains("://"))
path = path.Replace("/", "\\");

if (path.Contains("\\"))
dir = System.IO.Path.GetDirectoryName(path);
if (path.Contains("\\"))
dir = System.IO.Path.GetDirectoryName(path);

List<string> files = Directory.GetFiles(dir).ToList();
List<string> files = Directory.GetFiles(dir).ToList();

files = files.Where(file =>
VideoTypes.Contains(file.Ext()) ||
AudioTypes.Contains(file.Ext()) ||
ImageTypes.Contains(file.Ext())).ToList();
files = files.Where(file =>
VideoTypes.Contains(file.Ext()) ||
AudioTypes.Contains(file.Ext()) ||
ImageTypes.Contains(file.Ext())).ToList();

files.Sort(new StringLogicalComparer());
int index = files.IndexOf(path);
files.Remove(path);
files.Sort(new StringLogicalComparer());
int index = files.IndexOf(path);
files.Remove(path);

foreach (string i in files)
CommandV("loadfile", i, "append");
foreach (string i in files)
CommandV("loadfile", i, "append");

if (index > 0)
CommandV("playlist-move", "0", (index + 1).ToString());
if (index > 0)
CommandV("playlist-move", "0", (index + 1).ToString());
}
}

bool WasAviSynthLoaded;
Expand Down

0 comments on commit 40565e8

Please sign in to comment.