Skip to content

Commit fc00407

Browse files
cfsmp3claude
andcommitted
fix: Improve CCExtractor binary path resolution
- Fix path resolution to check bundled executable first, then fall back to system PATH (was incorrectly detecting non-executable files) - Add debug logging to extraction process for troubleshooting - Log CCExtractor stdout/stderr output for visibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f1d180a commit fc00407

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

lib/bloc/process_bloc/process_bloc.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
4242
}
4343

4444
void _extractNext(Emitter<ProcessState> emit) {
45+
logger.d('_extractNext called - started: ${state.started}, current: ${state.current}, queue: ${state.queue.length}');
46+
4547
if (!state.started || state.current != null || state.queue.isEmpty) {
4648
if (state.queue.isEmpty) {
49+
logger.d('Queue is empty, resetting state');
4750
emit(state.copyWith(
4851
queue: state.originalList,
4952
processed: state.processed,
@@ -55,6 +58,7 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
5558
return;
5659
}
5760
final file = state.queue.first;
61+
logger.i('Starting extraction for: ${file.path}');
5862
emit(state.copyWith(
5963
current: file,
6064
queue: state.queue.skip(1).toList(),
@@ -70,12 +74,15 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
7074
)
7175
.then(
7276
(value) {
77+
logger.i('Extraction completed with exit code: $value');
7378
if (value != 0) {
7479
add(ProcessError(value));
7580
}
7681
add(ProcessFileComplete(file));
7782
},
78-
);
83+
).catchError((e, stackTrace) {
84+
logger.e('Extraction failed', error: e, stackTrace: stackTrace);
85+
});
7986
}
8087

8188
void _extractOnNetwork(String type, String location, String tcppassword,

lib/repositories/ccextractor.dart

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,30 @@ class CCExtractor {
1717

1818
SettingsRepository settingsRepository = SettingsRepository();
1919
SettingsModel settings = SettingsModel();
20+
21+
/// Get the CCExtractor executable path.
22+
/// First checks for a bundled executable next to the app, then falls back
23+
/// to the system PATH.
2024
String get ccextractor {
21-
return Platform.isWindows ? './ccextractorwinfull.exe' : './ccextractor';
25+
final executableName =
26+
Platform.isWindows ? 'ccextractorwinfull.exe' : 'ccextractor';
27+
28+
// Try relative to the running executable (for packaged/bundled apps)
29+
final execDir = File(Platform.resolvedExecutable).parent.path;
30+
final execPath = '$execDir/$executableName';
31+
final execFile = File(execPath);
32+
if (execFile.existsSync()) {
33+
// Verify it's actually a file (not a directory) and exists
34+
final stat = execFile.statSync();
35+
if (stat.type == FileSystemEntityType.file) {
36+
logger.d('Found bundled CCExtractor at: $execPath');
37+
return execPath;
38+
}
39+
}
40+
41+
// Fall back to system PATH (most common case for installed ccextractor)
42+
logger.d('Using CCExtractor from system PATH: $executableName');
43+
return executableName;
2244
}
2345

2446
Future<int> extractFile(
@@ -30,24 +52,31 @@ class CCExtractor {
3052
settings = await settingsRepository.getSettings();
3153
List<String> paramsList =
3254
settingsRepository.getParamsList(settings, filePath: file.path);
33-
process = await Process.start(
34-
ccextractor,
35-
[
36-
file.path,
37-
'--gui-mode-reports',
38-
...paramsList,
39-
],
40-
);
55+
56+
final args = [
57+
file.path,
58+
'--gui-mode-reports',
59+
...paramsList,
60+
];
61+
logger.i('Starting CCExtractor: $ccextractor');
62+
logger.d('Arguments: $args');
63+
64+
try {
65+
process = await Process.start(ccextractor, args);
66+
} catch (e, stackTrace) {
67+
logger.e('Failed to start CCExtractor process', error: e, stackTrace: stackTrace);
68+
rethrow;
69+
}
4170
// sometimes stdout and stderr have important logs like how much time
4271
// it took to process the file or some erros not captured by exitcodes,
4372
// so just print them to the logs box
4473
process.stdout.transform(latin1.decoder).listen((update) {
45-
// print(update);
74+
logger.d('CCExtractor stdout: $update');
4675
listenOutput(update);
4776
});
4877

4978
process.stderr.transform(latin1.decoder).listen((update) {
50-
// print(update);
79+
logger.d('CCExtractor stderr: $update');
5180
if (progressRegx.hasMatch(update)) {
5281
for (RegExpMatch i in progressRegx.allMatches(update)) {
5382
listenProgress(i[1]!);

0 commit comments

Comments
 (0)