@@ -9,10 +9,10 @@ namespace ContextMenuUploader;
9
9
public class Program
10
10
{
11
11
private const string AppName = "ContextMenuUploader" ;
12
- private const int BatchTimeoutMs = 1000 ; // Timeout in milliseconds to wait for more files to be selected
12
+ private const int BatchTimeoutMs = 500 ; // Timeout in milliseconds to wait for more files to be selected
13
13
private const string ContextMenuLabel = "Upload to web service" ;
14
14
private const string MutexName = "Global\\ ContextMenuUploader" ;
15
- private static readonly string TempFilePath = Path . Combine ( Path . GetTempPath ( ) , "ContextMenuUploader.txt " ) ;
15
+ private static readonly string TempFilePath = Path . Combine ( Path . GetTempPath ( ) , "ContextMenuUploader" ) ;
16
16
17
17
[ STAThread ]
18
18
public static async Task Main ( string [ ] args )
@@ -44,8 +44,12 @@ public static async Task Main(string[] args)
44
44
45
45
private static async Task HandleFileActionAsync ( string [ ] newPaths )
46
46
{
47
- // Add new paths to the temporary file
48
- newPaths . SafelyWriteLinesToFile ( Program . TempFilePath , false ) ;
47
+ // Ensure the temporary directory exists
48
+ Directory . CreateDirectory ( Program . TempFilePath ) ;
49
+
50
+ // Add new paths to a temporary file
51
+ string randomFile = Path . Combine ( Program . TempFilePath , Path . GetRandomFileName ( ) ) ;
52
+ await File . AppendAllLinesAsync ( randomFile , newPaths ) ;
49
53
50
54
using Mutex mutex = new ( true , Program . MutexName , out bool createdNew ) ;
51
55
@@ -57,24 +61,28 @@ private static async Task HandleFileActionAsync(string[] newPaths)
57
61
// Waiting if more files/folders are selected
58
62
await Task . Delay ( Program . BatchTimeoutMs ) ;
59
63
60
- int previousCount , nextCount = ( await File . ReadAllLinesAsync ( Program . TempFilePath ) ) . Length ;
64
+ int previousCount , nextCount = Directory . GetFiles ( Program . TempFilePath ) . Length ;
61
65
62
66
// Wait until the number stops increasing
63
67
do
64
68
{
65
69
previousCount = nextCount ;
66
70
await Task . Delay ( Program . BatchTimeoutMs ) ;
67
- nextCount = ( await File . ReadAllLinesAsync ( Program . TempFilePath ) ) . Length ;
71
+ nextCount = Directory . GetFiles ( Program . TempFilePath ) . Length ;
68
72
}
69
73
while ( previousCount != nextCount ) ;
70
74
71
75
List < string > allPaths = new ( ) ;
72
76
73
- // Get all paths from the temporary file
74
- if ( File . Exists ( Program . TempFilePath ) )
77
+ // Get all paths from the temporary files
78
+ if ( Directory . Exists ( Program . TempFilePath ) )
75
79
{
76
- allPaths = ( await File . ReadAllLinesAsync ( Program . TempFilePath ) ) . ToList ( ) ;
77
- File . Delete ( Program . TempFilePath ) ;
80
+ foreach ( var file in Directory . GetFiles ( Program . TempFilePath ) )
81
+ {
82
+ allPaths . AddRange ( await File . ReadAllLinesAsync ( file ) ) ;
83
+ }
84
+
85
+ Directory . Delete ( Program . TempFilePath , true ) ;
78
86
}
79
87
80
88
int count = allPaths . Count ;
0 commit comments