21
21
import java .io .IOException ;
22
22
import java .nio .file .Files ;
23
23
import java .nio .file .Path ;
24
- import java .nio .file .StandardCopyOption ;
25
24
import java .text .DateFormat ;
26
25
import java .text .ParseException ;
27
26
import java .text .SimpleDateFormat ;
@@ -60,22 +59,17 @@ public class ConfigManager {
60
59
61
60
enum ConfigSaveStrategy {
62
61
SQL ,
63
- LEGACY ,
64
62
ATOMIC_ZIP
65
63
}
66
64
67
- // This logic decides which kind of ConfigManager we load as the default. If we
68
- // want to switch
69
- // back to the legacy config manager, change this constant
65
+ // This logic decides which kind of ConfigManager we load as the default.
70
66
private static final ConfigSaveStrategy m_saveStrat = ConfigSaveStrategy .SQL ;
71
67
72
68
public static ConfigManager getInstance () {
73
69
if (INSTANCE == null ) {
74
70
Path rootFolder = PathManager .getInstance ().getRootFolder ();
75
71
switch (m_saveStrat ) {
76
72
case SQL -> INSTANCE = new ConfigManager (rootFolder , new SqlConfigProvider (rootFolder ));
77
- case LEGACY ->
78
- INSTANCE = new ConfigManager (rootFolder , new LegacyConfigProvider (rootFolder ));
79
73
case ATOMIC_ZIP -> {
80
74
// TODO: Not done yet
81
75
}
@@ -86,58 +80,6 @@ public static ConfigManager getInstance() {
86
80
87
81
private static final Logger logger = new Logger (ConfigManager .class , LogGroup .Config );
88
82
89
- private void translateLegacyIfPresent (Path folderPath ) {
90
- if (!(m_provider instanceof SqlConfigProvider )) {
91
- // Cannot import into SQL if we aren't in SQL mode rn
92
- return ;
93
- }
94
-
95
- var maybeCams = Path .of (folderPath .toAbsolutePath ().toString (), "cameras" ).toFile ();
96
- var maybeCamsBak = Path .of (folderPath .toAbsolutePath ().toString (), "cameras_backup" ).toFile ();
97
-
98
- if (maybeCams .exists () && maybeCams .isDirectory ()) {
99
- logger .info ("Translating settings zip!" );
100
- var legacy = new LegacyConfigProvider (folderPath );
101
- legacy .load ();
102
- var loadedConfig = legacy .getConfig ();
103
-
104
- // yeet our current cameras directory, not needed anymore
105
- if (maybeCamsBak .exists ()) FileUtils .deleteDirectory (maybeCamsBak .toPath ());
106
- if (!maybeCams .canWrite ()) {
107
- maybeCams .setWritable (true );
108
- }
109
-
110
- try {
111
- Files .move (maybeCams .toPath (), maybeCamsBak .toPath (), StandardCopyOption .REPLACE_EXISTING );
112
- } catch (IOException e ) {
113
- logger .error ("Exception moving cameras to cameras_bak!" , e );
114
-
115
- // Try to just copy from cams to cams-bak instead of moving? Windows sometimes
116
- // needs us to
117
- // do that
118
- try {
119
- org .apache .commons .io .FileUtils .copyDirectory (maybeCams , maybeCamsBak );
120
- } catch (IOException e1 ) {
121
- // So we can't move to cams_bak, and we can't copy and delete either? We just
122
- // have to give
123
- // up here on preserving the old folder
124
- logger .error ("Exception while backup-copying cameras to cameras_bak!" , e );
125
- e1 .printStackTrace ();
126
- }
127
-
128
- // Delete the directory because we were successfully able to load the config but
129
- // were unable
130
- // to save or copy the folder.
131
- if (maybeCams .exists ()) FileUtils .deleteDirectory (maybeCams .toPath ());
132
- }
133
-
134
- // Save the same config out using SQL loader
135
- var sql = new SqlConfigProvider (getRootFolder ());
136
- sql .setConfig (loadedConfig );
137
- sql .saveToDisk ();
138
- }
139
- }
140
-
141
83
public static boolean nukeConfigDirectory () {
142
84
return FileUtils .deleteDirectory (getRootFolder ());
143
85
}
@@ -153,27 +95,13 @@ public static boolean saveUploadedSettingsZip(File uploadPath) {
153
95
return false ;
154
96
}
155
97
156
- // If there's a cameras folder in the upload, we know we need to import from the
157
- // old style
158
- var maybeCams = Path .of (folderPath .getAbsolutePath (), "cameras" ).toFile ();
159
- if (maybeCams .exists () && maybeCams .isDirectory ()) {
160
- var legacy = new LegacyConfigProvider (folderPath .toPath ());
161
- legacy .load ();
162
- var loadedConfig = legacy .getConfig ();
163
-
164
- var sql = new SqlConfigProvider (getRootFolder ());
165
- sql .setConfig (loadedConfig );
166
- return sql .saveToDisk ();
167
- } else {
168
- // new structure -- just copy and save like we used to
169
- try {
170
- org .apache .commons .io .FileUtils .copyDirectory (folderPath , getRootFolder ().toFile ());
171
- logger .info ("Copied settings successfully!" );
172
- return true ;
173
- } catch (IOException e ) {
174
- logger .error ("Exception copying uploaded settings!" , e );
175
- return false ;
176
- }
98
+ try {
99
+ org .apache .commons .io .FileUtils .copyDirectory (folderPath , getRootFolder ().toFile ());
100
+ logger .info ("Copied settings successfully!" );
101
+ return true ;
102
+ } catch (IOException e ) {
103
+ logger .error ("Exception copying uploaded settings!" , e );
104
+ return false ;
177
105
}
178
106
}
179
107
@@ -194,7 +122,6 @@ private static Path getRootFolder() {
194
122
}
195
123
196
124
public void load () {
197
- translateLegacyIfPresent (this .configDirectoryFile .toPath ());
198
125
m_provider .load ();
199
126
}
200
127
0 commit comments