Skip to content

Commit b3bc0e6

Browse files
committed
rip out legacy config provider
1 parent 7d927ac commit b3bc0e6

File tree

6 files changed

+15
-628
lines changed

6 files changed

+15
-628
lines changed

photon-core/src/main/java/org/photonvision/common/configuration/CameraConfiguration.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.fasterxml.jackson.annotation.JsonCreator;
2121
import com.fasterxml.jackson.annotation.JsonIgnore;
2222
import com.fasterxml.jackson.annotation.JsonProperty;
23-
import edu.wpi.first.cscore.UsbCameraInfo;
2423
import java.util.ArrayList;
2524
import java.util.List;
2625
import java.util.UUID;
@@ -115,33 +114,6 @@ public CameraConfiguration(PVCameraInfo camInfo) {
115114
this(UUID.randomUUID().toString(), camInfo);
116115
}
117116

118-
public static class LegacyCameraConfigStruct {
119-
PVCameraInfo matchedCameraInfo;
120-
121-
/** Legacy constructor for compat with 2024.3.1 */
122-
@JsonCreator
123-
public LegacyCameraConfigStruct(
124-
@JsonProperty("baseName") String baseName,
125-
@JsonProperty("path") String path,
126-
@JsonProperty("otherPaths") String[] otherPaths,
127-
@JsonProperty("cameraType") CameraType cameraType,
128-
@JsonProperty("usbVID") int usbVID,
129-
@JsonProperty("usbPID") int usbPID) {
130-
if (cameraType == CameraType.UsbCamera) {
131-
this.matchedCameraInfo =
132-
PVCameraInfo.fromUsbCameraInfo(
133-
new UsbCameraInfo(-1, path, baseName, otherPaths, usbVID, usbPID));
134-
} else if (cameraType == CameraType.ZeroCopyPicam) {
135-
this.matchedCameraInfo = PVCameraInfo.fromCSICameraInfo(path, baseName);
136-
} else {
137-
// wtf
138-
logger.error("Camera type is invalid");
139-
this.matchedCameraInfo = null;
140-
return;
141-
}
142-
}
143-
}
144-
145117
public void addPipelineSettings(List<CVPipelineSettings> settings) {
146118
for (var setting : settings) {
147119
addPipelineSetting(setting);

photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
24-
import java.nio.file.StandardCopyOption;
2524
import java.text.DateFormat;
2625
import java.text.ParseException;
2726
import java.text.SimpleDateFormat;
@@ -60,22 +59,17 @@ public class ConfigManager {
6059

6160
enum ConfigSaveStrategy {
6261
SQL,
63-
LEGACY,
6462
ATOMIC_ZIP
6563
}
6664

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.
7066
private static final ConfigSaveStrategy m_saveStrat = ConfigSaveStrategy.SQL;
7167

7268
public static ConfigManager getInstance() {
7369
if (INSTANCE == null) {
7470
Path rootFolder = PathManager.getInstance().getRootFolder();
7571
switch (m_saveStrat) {
7672
case SQL -> INSTANCE = new ConfigManager(rootFolder, new SqlConfigProvider(rootFolder));
77-
case LEGACY ->
78-
INSTANCE = new ConfigManager(rootFolder, new LegacyConfigProvider(rootFolder));
7973
case ATOMIC_ZIP -> {
8074
// TODO: Not done yet
8175
}
@@ -86,58 +80,6 @@ public static ConfigManager getInstance() {
8680

8781
private static final Logger logger = new Logger(ConfigManager.class, LogGroup.Config);
8882

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-
14183
public static boolean nukeConfigDirectory() {
14284
return FileUtils.deleteDirectory(getRootFolder());
14385
}
@@ -153,27 +95,13 @@ public static boolean saveUploadedSettingsZip(File uploadPath) {
15395
return false;
15496
}
15597

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;
177105
}
178106
}
179107

@@ -194,7 +122,6 @@ private static Path getRootFolder() {
194122
}
195123

196124
public void load() {
197-
translateLegacyIfPresent(this.configDirectoryFile.toPath());
198125
m_provider.load();
199126
}
200127

0 commit comments

Comments
 (0)