Skip to content

Commit

Permalink
drag/drop folders
Browse files Browse the repository at this point in the history
  • Loading branch information
tigros committed Aug 27, 2024
1 parent 2aa5bdd commit 29df206
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
89 changes: 72 additions & 17 deletions whisperer/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
using System.IO.Pipes;
using System.Media;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TaskScheduler;

Expand Down Expand Up @@ -139,8 +141,10 @@ void loadfilelist()
string s = readreg("files", "");
string[] files = s.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
fastObjectListView1.BeginUpdate();
List<filenameline> items = new List<filenameline>();
foreach (string file in files)
fastObjectListView1.AddObject(new filenameline(file));
items.Add(new filenameline(file));
fastObjectListView1.AddObjects(items);
fastObjectListView1.EndUpdate();
fastObjectListView1.SelectAll();
setcount();
Expand Down Expand Up @@ -273,28 +277,22 @@ void fillmemvars()
freemem = getfreegpumem();
}

bool fexists(string name)
{
for (int i = 0; i < fastObjectListView1.Items.Count; i++)
{
string s = fastObjectListView1.Items[i].Text;
if (name == s)
return true;
}
return false;
}

void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Cursor = Cursors.WaitCursor;
fastObjectListView1.BeginUpdate();
filllookup();
foreach (string filename in openFileDialog1.FileNames)
{
if (!fexists(filename))
if (!filelookup.ContainsKey(filename))
{
fastObjectListView1.AddObject(new filenameline(filename));
filelookup.TryAdd(filename, true);
}
}
filelookup.Clear();
fastObjectListView1.EndUpdate();
fastObjectListView1.SelectAll();
setcount();
Expand Down Expand Up @@ -1033,6 +1031,35 @@ void fastObjectListView1_SelectionChanged(object sender, EventArgs e)
setcount();
}

ConcurrentBag<string> tmpbag = new ConcurrentBag<string>();
void ReadFileList(string rootFolderPath, ParallelLoopState state1 = null)
{
try
{
if ((File.GetAttributes(rootFolderPath) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
{

var files = Directory.GetFiles(rootFolderPath);
Parallel.ForEach(files, (string afile, ParallelLoopState state) =>
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
if (issoundtype(afile) && !filelookup.ContainsKey(afile))
{
tmpbag.Add(afile);
filelookup.TryAdd(afile, true);
}
});

var directories = Directory.GetDirectories(rootFolderPath);
Parallel.ForEach(directories, ReadFileList);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}

void fastObjectListView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
Expand All @@ -1041,15 +1068,43 @@ void fastObjectListView1_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.None;
}

void loadbag()
{
List<filenameline> items = new List<filenameline>();
string file;
while (tmpbag.TryTake(out file))
items.Add(new filenameline(file));
fastObjectListView1.AddObjects(items);
}

ConcurrentDictionary<string, bool> filelookup = new ConcurrentDictionary<string, bool>();
void filllookup()
{
filelookup.Clear();
for (int i = 0; i < fastObjectListView1.Items.Count; i++)
{
string filename = fastObjectListView1.Items[i].Text;
filelookup.TryAdd(filename, true);
}
}

void fastObjectListView1_DragDrop(object sender, DragEventArgs e)
{
Cursor = Cursors.WaitCursor;
fastObjectListView1.BeginUpdate();
filllookup();
foreach (string file in (string[])e.Data.GetData(DataFormats.FileDrop))
{
if (!fexists(file))
if ((File.GetAttributes(file) & FileAttributes.Directory) == FileAttributes.Directory)
ReadFileList(file);
else if (!filelookup.ContainsKey(file))
{
fastObjectListView1.AddObject(new filenameline(file));
filelookup.TryAdd(file, true);
}
}
loadbag();
filelookup.Clear();
fastObjectListView1.EndUpdate();
fastObjectListView1.SelectAll();
setcount();
Expand Down Expand Up @@ -1087,10 +1142,10 @@ void timer1_Tick(object sender, EventArgs e)

void savefilelist()
{
string s = "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fastObjectListView1.Items.Count; i++)
s += fastObjectListView1.Items[i].Text + ";";
writereg("files", s.TrimEnd(';'));
sb.Append(fastObjectListView1.Items[i].Text + ";");
writereg("files", sb.ToString().TrimEnd(';'));
}

void savesettings()
Expand Down
6 changes: 3 additions & 3 deletions whisperer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Whisperer")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.4.0.0")]
[assembly: AssemblyFileVersion("3.4.0.0")]
[assembly: AssemblyVersion("3.5.0.0")]
[assembly: AssemblyFileVersion("3.5.0.0")]

0 comments on commit 29df206

Please sign in to comment.