Skip to content

remove legacy config #1904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.cscore.UsbCameraInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -115,33 +114,6 @@ public CameraConfiguration(PVCameraInfo camInfo) {
this(UUID.randomUUID().toString(), camInfo);
}

public static class LegacyCameraConfigStruct {
PVCameraInfo matchedCameraInfo;

/** Legacy constructor for compat with 2024.3.1 */
@JsonCreator
public LegacyCameraConfigStruct(
@JsonProperty("baseName") String baseName,
@JsonProperty("path") String path,
@JsonProperty("otherPaths") String[] otherPaths,
@JsonProperty("cameraType") CameraType cameraType,
@JsonProperty("usbVID") int usbVID,
@JsonProperty("usbPID") int usbPID) {
if (cameraType == CameraType.UsbCamera) {
this.matchedCameraInfo =
PVCameraInfo.fromUsbCameraInfo(
new UsbCameraInfo(-1, path, baseName, otherPaths, usbVID, usbPID));
} else if (cameraType == CameraType.ZeroCopyPicam) {
this.matchedCameraInfo = PVCameraInfo.fromCSICameraInfo(path, baseName);
} else {
// wtf
logger.error("Camera type is invalid");
this.matchedCameraInfo = null;
return;
}
}
}

public void addPipelineSettings(List<CVPipelineSettings> settings) {
for (var setting : settings) {
addPipelineSetting(setting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -51,28 +49,27 @@ public class ConfigManager {
private final Thread settingsSaveThread;
private long saveRequestTimestamp = -1;

// special case flag to disable flushing settings to disk at shutdown. Avoids the jvm shutdown
// special case flag to disable flushing settings to disk at shutdown. Avoids
// the jvm shutdown
// hook overwriting the settings we just uploaded
private boolean flushOnShutdown = true;
private boolean allowWriteTask = true;

enum ConfigSaveStrategy {
SQL,
LEGACY,

ATOMIC_ZIP
}

// This logic decides which kind of ConfigManager we load as the default. If we want to switch
// back to the legacy config manager, change this constant
// This logic decides which kind of ConfigManager we load as the default. Legacy used to be an
// option, but it was removed on Apr 15 2025.
private static final ConfigSaveStrategy m_saveStrat = ConfigSaveStrategy.SQL;

public static ConfigManager getInstance() {
if (INSTANCE == null) {
Path rootFolder = PathManager.getInstance().getRootFolder();
switch (m_saveStrat) {
case SQL -> INSTANCE = new ConfigManager(rootFolder, new SqlConfigProvider(rootFolder));
case LEGACY ->
INSTANCE = new ConfigManager(rootFolder, new LegacyConfigProvider(rootFolder));
case ATOMIC_ZIP -> {
// TODO: Not done yet
}
Expand All @@ -83,55 +80,6 @@ public static ConfigManager getInstance() {

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

private void translateLegacyIfPresent(Path folderPath) {
if (!(m_provider instanceof SqlConfigProvider)) {
// Cannot import into SQL if we aren't in SQL mode rn
return;
}

var maybeCams = Path.of(folderPath.toAbsolutePath().toString(), "cameras").toFile();
var maybeCamsBak = Path.of(folderPath.toAbsolutePath().toString(), "cameras_backup").toFile();

if (maybeCams.exists() && maybeCams.isDirectory()) {
logger.info("Translating settings zip!");
var legacy = new LegacyConfigProvider(folderPath);
legacy.load();
var loadedConfig = legacy.getConfig();

// yeet our current cameras directory, not needed anymore
if (maybeCamsBak.exists()) FileUtils.deleteDirectory(maybeCamsBak.toPath());
if (!maybeCams.canWrite()) {
maybeCams.setWritable(true);
}

try {
Files.move(maybeCams.toPath(), maybeCamsBak.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
logger.error("Exception moving cameras to cameras_bak!", e);

// Try to just copy from cams to cams-bak instead of moving? Windows sometimes needs us to
// do that
try {
org.apache.commons.io.FileUtils.copyDirectory(maybeCams, maybeCamsBak);
} catch (IOException e1) {
// So we can't move to cams_bak, and we can't copy and delete either? We just have to give
// up here on preserving the old folder
logger.error("Exception while backup-copying cameras to cameras_bak!", e);
e1.printStackTrace();
}

// Delete the directory because we were successfully able to load the config but were unable
// to save or copy the folder.
if (maybeCams.exists()) FileUtils.deleteDirectory(maybeCams.toPath());
}

// Save the same config out using SQL loader
var sql = new SqlConfigProvider(getRootFolder());
sql.setConfig(loadedConfig);
sql.saveToDisk();
}
}

public static boolean nukeConfigDirectory() {
return FileUtils.deleteDirectory(getRootFolder());
}
Expand All @@ -147,27 +95,14 @@ public static boolean saveUploadedSettingsZip(File uploadPath) {
return false;
}

// If there's a cameras folder in the upload, we know we need to import from the
// old style
var maybeCams = Path.of(folderPath.getAbsolutePath(), "cameras").toFile();
if (maybeCams.exists() && maybeCams.isDirectory()) {
var legacy = new LegacyConfigProvider(folderPath.toPath());
legacy.load();
var loadedConfig = legacy.getConfig();

var sql = new SqlConfigProvider(getRootFolder());
sql.setConfig(loadedConfig);
return sql.saveToDisk();
} else {
// new structure -- just copy and save like we used to
try {
org.apache.commons.io.FileUtils.copyDirectory(folderPath, getRootFolder().toFile());
logger.info("Copied settings successfully!");
return true;
} catch (IOException e) {
logger.error("Exception copying uploaded settings!", e);
return false;
}
// new structure -- just copy and save like we used to
try {
org.apache.commons.io.FileUtils.copyDirectory(folderPath, getRootFolder().toFile());
logger.info("Copied settings successfully!");
return true;
} catch (IOException e) {
logger.error("Exception copying uploaded settings!", e);
return false;
}
}

Expand All @@ -188,7 +123,6 @@ private static Path getRootFolder() {
}

public void load() {
translateLegacyIfPresent(this.configDirectoryFile.toPath());
m_provider.load();
}

Expand Down
Loading
Loading