|
1 | 1 | function success = uninstall() |
2 | | - % Remove MHKiT environment fixes from MATLAB startup script |
| 2 | + % Remove MHKiT environment fixes from MATLAB startup script using shared utilities |
3 | 3 |
|
4 | | - [startup_file, ~] = get_startup_file_location(); |
| 4 | + % Get spec for constants |
| 5 | + spec = mhkit.spec(); |
5 | 6 |
|
6 | | - if ~exist(startup_file, 'file') || ~has_mhkit_fixes(startup_file) |
| 7 | + % Get startup file location using shared utility |
| 8 | + [~, startup_file] = mhkit.matlab.get_matlab_user_directory(spec); |
| 9 | + |
| 10 | + if ~has_mhkit_fixes(startup_file, spec) |
7 | 11 | fprintf('No MHKiT fixes found to remove.\n'); |
8 | 12 | success = true; |
9 | 13 | return; |
10 | 14 | end |
11 | 15 |
|
12 | | - success = remove_mhkit_fixes(startup_file); |
| 16 | + success = remove_mhkit_fixes(startup_file, spec); |
13 | 17 |
|
14 | 18 | if success |
15 | 19 | fprintf('✓ Removed MHKiT fixes from: %s\n', startup_file); |
|
19 | 23 | end |
20 | 24 | end |
21 | 25 |
|
22 | | -function [startup_file, matlab_user_dir] = get_startup_file_location() |
23 | | - matlab_user_dir = userpath; |
24 | | - if isempty(matlab_user_dir) |
25 | | - if ispc |
26 | | - matlab_user_dir = fullfile(getenv('USERPROFILE'), 'Documents', 'MATLAB'); |
27 | | - else |
28 | | - matlab_user_dir = fullfile(getenv('HOME'), 'Documents', 'MATLAB'); |
29 | | - end |
30 | | - else |
31 | | - matlab_user_dir = strtrim(matlab_user_dir); |
32 | | - if endsWith(matlab_user_dir, pathsep) |
33 | | - matlab_user_dir = matlab_user_dir(1:end-1); |
34 | | - end |
35 | | - end |
36 | | - startup_file = fullfile(matlab_user_dir, 'startup.m'); |
37 | | -end |
| 26 | +function has_fixes = has_mhkit_fixes(startup_file, spec) |
| 27 | + % Check if startup.m contains MHKiT fixes using shared utilities |
38 | 28 |
|
39 | | -function has_fixes = has_mhkit_fixes(startup_file) |
40 | | - has_fixes = false; |
41 | | - try |
42 | | - fid = fopen(startup_file, 'r'); |
43 | | - if fid == -1, return; end |
44 | | - content = fread(fid, '*char')'; |
45 | | - fclose(fid); |
46 | | - has_fixes = contains(content, '%% MHKiT Environment Setup - START'); |
47 | | - catch |
| 29 | + [success, content] = mhkit.io.read_file_safe(startup_file); |
| 30 | + if ~success |
| 31 | + has_fixes = false; |
| 32 | + return; |
48 | 33 | end |
49 | | -end |
50 | 34 |
|
51 | | -function success = remove_mhkit_fixes(startup_file) |
52 | | - success = false; |
53 | | - try |
54 | | - fid = fopen(startup_file, 'r'); |
55 | | - if fid == -1, return; end |
56 | | - content = fread(fid, '*char')'; |
57 | | - fclose(fid); |
| 35 | + start_marker = spec.constants.startup_script.start_marker; |
| 36 | + has_fixes = contains(content, start_marker); |
| 37 | +end |
58 | 38 |
|
59 | | - cleaned_content = remove_mhkit_section(content); |
| 39 | +function success = remove_mhkit_fixes(startup_file, spec) |
| 40 | + % Remove MHKiT fixes using shared utilities |
60 | 41 |
|
61 | | - fid = fopen(startup_file, 'w'); |
62 | | - if fid == -1, return; end |
63 | | - fprintf(fid, '%s', cleaned_content); |
64 | | - fclose(fid); |
65 | | - success = true; |
66 | | - catch |
| 42 | + [read_success, content] = mhkit.io.read_file_safe(startup_file); |
| 43 | + if ~read_success |
| 44 | + success = false; |
| 45 | + return; |
67 | 46 | end |
| 47 | + |
| 48 | + cleaned_content = remove_mhkit_section(content, spec); |
| 49 | + success = mhkit.io.write_file_safe(startup_file, cleaned_content); |
68 | 50 | end |
69 | 51 |
|
70 | | -function cleaned_content = remove_mhkit_section(content) |
71 | | - start_marker = '%% MHKiT Environment Setup - START'; |
72 | | - end_marker = '%% MHKiT Environment Setup - END'; |
| 52 | +function cleaned_content = remove_mhkit_section(content, spec) |
| 53 | + % Remove MHKiT section using constants from spec |
| 54 | + |
| 55 | + start_marker = spec.constants.startup_script.start_marker; |
| 56 | + end_marker = spec.constants.startup_script.end_marker; |
73 | 57 |
|
74 | 58 | start_pos = strfind(content, start_marker); |
75 | 59 | end_pos = strfind(content, end_marker); |
|
0 commit comments