-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfar2l_import.pl
executable file
·104 lines (85 loc) · 2.85 KB
/
far2l_import.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
#use Data::Dumper qw(Dumper);
use File::Path qw(remove_tree make_path);
my $filename = shift or die "Usage: far2l_import.pl color_scheme.reg\nNeeds legacy REGEDIT4 format\n\n";
print "Importing " . $filename . "\n";
my @array;
open(my $fh, "<", $filename)
or die "Failed to open file: $!\n";
while(<$fh>) {
chomp;
push @array, $_;
}
close $fh;
# reset colors
remove_tree($ENV{'HOME'} . "/.config/far2l/REG/HKU/c/k-Software/k-Far2/k-Colors");
$param = '';
foreach (@array) {
$_ =~ s/[\x0A\x0D]//g;
$first = substr($_, 0, 1);
if ($first eq 'R') {
} elsif ($first eq '[') {
$group = $_;
$group = substr( $group, 1, (length($group) - 2 ) );
my @path = split /\\/, $group;
$path_str = $ENV{'HOME'} . "/.config/far2l/REG/";
foreach (@path) {
if ($_ eq 'HKEY_CURRENT_USER') {
$path_str_part = 'HKU/c/';
} elsif ($_ eq 'Far') {
$path_str_part = 'k-Far2/';
} elsif ($_ eq 'far2') {
$path_str_part = 'k-Far2/';
} else {
$path_str_part = 'k-' . $_ . '/';
}
$path_str .= $path_str_part;
make_path($path_str);
}
} elsif ($first eq '"') {
my @parts = split /=/, $_;
$param = $parts[0];
$param =~ s/"(.*?)"/$1/s;
$val = $parts[1];
$first2 = substr($val, 0, 1);
if ($first2 eq '"') {
$val = substr( $val, 1, (length($val) - 2) );
open(FH, '>', $path_str . 'v-' . $param) or die $!;
print FH $param . "\n";
print FH "SZ\n";
print FH $val . '\0' . "\n";
close(FH);
} else {
my ($type, $value) = split /:/, $val;
if ($type eq 'dword') {
open(FH, '>', $path_str . 'v-' . $param) or die $!;
print FH $param . "\n";
print FH "DWORD\n";
print FH $value . "\n";
close(FH);
} elsif ($type eq 'hex') {
$continues = (substr($value, -1) eq '\'');
$value =~ tr/,/ /;
$value =~ tr/\\/ /;
open(FH, '>', $path_str . 'v-' . $param) or die $!;
print FH $param . "\n";
print FH "BINARY\n";
$value =~ s/^\s+|\s+$//g;
print FH $value;
if (!$continues) { print FH "\n"; }
close(FH);
}
}
} elsif ($first eq ' ') {
# hex, continued
$value = $_;
$continues = (substr($value, -1) eq '\'');
$value =~ tr/,/ /;
$value =~ tr/\\/ /;
open(FH, '>>', $path_str . 'v-' . $param) or die $!;
$value =~ s/^\s+|\s+$//g;
print FH $value;
if (!$continues) { print FH "\n"; }
close(FH);
}
}