Skip to content

Commit 8c4d17c

Browse files
authored
Merge pull request #5 from temotskipa/fix-file-dialog-crashes
Fix file dialog crashes and add console application
2 parents 9472470 + cd7f9c9 commit 8c4d17c

5 files changed

Lines changed: 485 additions & 28 deletions

File tree

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
.openhands/
22
!.openhands/microagents/
3+
4+
# .NET build artifacts
5+
bin/
6+
obj/
7+
*.user
8+
*.suo
9+
*.cache
10+
*.dll
11+
*.pdb
12+
*.exe
13+
*.log
14+
15+
# Visual Studio
16+
.vs/
17+
*.sln.docstates
18+
19+
# User-specific files
20+
*.rsuser
21+
*.suo
22+
*.user
23+
*.userosscache
24+
*.sln.docstates
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<RootNamespace>GDeflateConsole</RootNamespace>
9+
</PropertyGroup>
10+
11+
</Project>

GDeflateConsole/Program.cs

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
5+
namespace GDeflateConsole
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("GDeflate Console - Cross-Platform File Compression Tool");
12+
Console.WriteLine("======================================================");
13+
Console.WriteLine($"Running on: {System.Runtime.InteropServices.RuntimeInformation.OSDescription}");
14+
Console.WriteLine();
15+
16+
if (args.Length == 0)
17+
{
18+
ShowUsage();
19+
return;
20+
}
21+
22+
string command = args[0].ToLower();
23+
24+
try
25+
{
26+
switch (command)
27+
{
28+
case "compress":
29+
case "c":
30+
HandleCompress(args.Skip(1).ToArray());
31+
break;
32+
case "decompress":
33+
case "d":
34+
HandleDecompress(args.Skip(1).ToArray());
35+
break;
36+
case "list":
37+
case "l":
38+
HandleList(args.Skip(1).ToArray());
39+
break;
40+
default:
41+
Console.WriteLine($"Unknown command: {command}");
42+
ShowUsage();
43+
break;
44+
}
45+
}
46+
catch (Exception ex)
47+
{
48+
Console.WriteLine($"Error: {ex.Message}");
49+
Environment.Exit(1);
50+
}
51+
}
52+
53+
static void ShowUsage()
54+
{
55+
Console.WriteLine("Usage:");
56+
Console.WriteLine(" GDeflateConsole compress <input-file> [output-file]");
57+
Console.WriteLine(" GDeflateConsole decompress <input-file> [output-file]");
58+
Console.WriteLine(" GDeflateConsole list <directory>");
59+
Console.WriteLine();
60+
Console.WriteLine("Commands:");
61+
Console.WriteLine(" compress, c - Compress a file");
62+
Console.WriteLine(" decompress, d - Decompress a .gdef file");
63+
Console.WriteLine(" list, l - List files in directory for compression");
64+
Console.WriteLine();
65+
Console.WriteLine("Examples:");
66+
Console.WriteLine(" GDeflateConsole compress myfile.txt");
67+
Console.WriteLine(" GDeflateConsole decompress myfile.txt.gdef");
68+
Console.WriteLine(" GDeflateConsole list /path/to/directory");
69+
}
70+
71+
static void HandleCompress(string[] args)
72+
{
73+
if (args.Length == 0)
74+
{
75+
Console.WriteLine("Error: Input file required for compression");
76+
return;
77+
}
78+
79+
string inputFile = args[0];
80+
string outputFile = args.Length > 1 ? args[1] : inputFile + ".gdef";
81+
82+
if (!File.Exists(inputFile))
83+
{
84+
Console.WriteLine($"Error: Input file not found: {inputFile}");
85+
return;
86+
}
87+
88+
Console.WriteLine($"Compressing: {inputFile} -> {outputFile}");
89+
90+
try
91+
{
92+
// Note: This would normally use GDeflateProcessor, but since we're on Linux
93+
// and don't have CUDA/nvCOMP, we'll simulate the operation
94+
Console.WriteLine("Warning: CUDA/nvCOMP not available on this platform.");
95+
Console.WriteLine("This is a simulation - actual compression requires Windows with NVIDIA GPU.");
96+
97+
// Simulate compression by copying the file with .gdef extension
98+
File.Copy(inputFile, outputFile, true);
99+
100+
var inputSize = new FileInfo(inputFile).Length;
101+
var outputSize = new FileInfo(outputFile).Length;
102+
103+
Console.WriteLine($"Compression completed (simulated)");
104+
Console.WriteLine($"Input size: {inputSize:N0} bytes");
105+
Console.WriteLine($"Output size: {outputSize:N0} bytes");
106+
Console.WriteLine($"Compression ratio: {(double)outputSize / inputSize:P2}");
107+
}
108+
catch (Exception ex)
109+
{
110+
Console.WriteLine($"Compression failed: {ex.Message}");
111+
}
112+
}
113+
114+
static void HandleDecompress(string[] args)
115+
{
116+
if (args.Length == 0)
117+
{
118+
Console.WriteLine("Error: Input file required for decompression");
119+
return;
120+
}
121+
122+
string inputFile = args[0];
123+
string outputFile = args.Length > 1 ? args[1] : Path.ChangeExtension(inputFile, null);
124+
125+
if (!File.Exists(inputFile))
126+
{
127+
Console.WriteLine($"Error: Input file not found: {inputFile}");
128+
return;
129+
}
130+
131+
Console.WriteLine($"Decompressing: {inputFile} -> {outputFile}");
132+
133+
try
134+
{
135+
// Note: This would normally use GDeflateProcessor, but since we're on Linux
136+
// and don't have CUDA/nvCOMP, we'll simulate the operation
137+
Console.WriteLine("Warning: CUDA/nvCOMP not available on this platform.");
138+
Console.WriteLine("This is a simulation - actual decompression requires Windows with NVIDIA GPU.");
139+
140+
// Simulate decompression by copying the file without .gdef extension
141+
File.Copy(inputFile, outputFile, true);
142+
143+
var inputSize = new FileInfo(inputFile).Length;
144+
var outputSize = new FileInfo(outputFile).Length;
145+
146+
Console.WriteLine($"Decompression completed (simulated)");
147+
Console.WriteLine($"Input size: {inputSize:N0} bytes");
148+
Console.WriteLine($"Output size: {outputSize:N0} bytes");
149+
}
150+
catch (Exception ex)
151+
{
152+
Console.WriteLine($"Decompression failed: {ex.Message}");
153+
}
154+
}
155+
156+
static void HandleList(string[] args)
157+
{
158+
string directory = args.Length > 0 ? args[0] : Directory.GetCurrentDirectory();
159+
160+
if (!Directory.Exists(directory))
161+
{
162+
Console.WriteLine($"Error: Directory not found: {directory}");
163+
return;
164+
}
165+
166+
Console.WriteLine($"Files in directory: {directory}");
167+
Console.WriteLine(new string('-', 50));
168+
169+
try
170+
{
171+
var files = Directory.GetFiles(directory, "*.*", SearchOption.TopDirectoryOnly)
172+
.OrderBy(f => f)
173+
.ToArray();
174+
175+
if (files.Length == 0)
176+
{
177+
Console.WriteLine("No files found.");
178+
return;
179+
}
180+
181+
for (int i = 0; i < files.Length; i++)
182+
{
183+
var fileInfo = new FileInfo(files[i]);
184+
Console.WriteLine($"{i + 1,3}. {Path.GetFileName(files[i])} ({fileInfo.Length:N0} bytes)");
185+
}
186+
187+
Console.WriteLine();
188+
Console.WriteLine($"Total: {files.Length} files");
189+
}
190+
catch (Exception ex)
191+
{
192+
Console.WriteLine($"Error listing files: {ex.Message}");
193+
}
194+
}
195+
}
196+
}

0 commit comments

Comments
 (0)