Slightly improve file selection.
This commit is contained in:
1 parent
4f34ebab60
commit
d1fccd3ea1
2 files changed
+58
-9
No files matched your search
@@ -48,15 +48,64 @@ Analyser::Static::TargetList Analyser::Static::TandyCoCo::GetTargets(
|
||||
if(!media.disks.empty()) {
|
||||
target->has_disk_drive = true;
|
||||
|
||||
const auto directory = Storage::Disk::TandyCoCo::directory(*media.disks.front());
|
||||
if(directory.has_value() && directory->size() == 1) {
|
||||
auto &entry = directory.value()[0];
|
||||
const bool is_basic = entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC;
|
||||
auto loadable = [&]() -> std::optional<Storage::Disk::TandyCoCo::DirectoryEntry> {
|
||||
const auto maybe_directory = Storage::Disk::TandyCoCo::directory(*media.disks.front());
|
||||
if(!maybe_directory.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto directory = *maybe_directory;
|
||||
|
||||
target->loading_command = is_basic ? L"LOAD\"" : L"LOADM\"";
|
||||
target->loading_command += std::wstring(entry.name.begin(), entry.name.end());
|
||||
target->loading_command += L"\":";
|
||||
target->loading_command += is_basic ? L"RUN\n" : L"EXEC\n";
|
||||
// Remove anything the user can't actually type.
|
||||
std::erase_if(directory, [](const auto &entry) {
|
||||
if(entry.name == " ") return true;
|
||||
for(const auto c: entry.name) {
|
||||
if(c & 0x80) return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Single item: return that.
|
||||
if(directory.size() == 1) {
|
||||
return directory[0];
|
||||
}
|
||||
|
||||
// Failing that, is there a single thing that's BASIC or no BASIC and a single thing that's machine code?
|
||||
int basics = 0;
|
||||
int machine_languages = 0;
|
||||
for(const auto &entry: directory) {
|
||||
basics += entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC;
|
||||
machine_languages +=
|
||||
entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::MachineLanguage;
|
||||
}
|
||||
|
||||
if(basics == 1) {
|
||||
for(const auto &entry: directory) {
|
||||
if(entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!basics && machine_languages == 1) {
|
||||
for(const auto &entry: directory) {
|
||||
if(entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::MachineLanguage) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
} ();
|
||||
|
||||
if(loadable.has_value()) {
|
||||
const bool is_basic = loadable->file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC;
|
||||
|
||||
target->loading_command = is_basic ? L"RUN\"" : L"LOADM\"";
|
||||
target->loading_command += std::wstring(loadable->name.begin(), loadable->name.end());
|
||||
if(!is_basic) {
|
||||
target->loading_command += L"\":EXEC";
|
||||
}
|
||||
target->loading_command += L"\n";
|
||||
} else {
|
||||
target->loading_command = L"DIR\n";
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ struct DirectoryEntry {
|
||||
BASIC = 0,
|
||||
BASICData = 1,
|
||||
MachineLanguage = 2,
|
||||
TextEditorsource = 3,
|
||||
TextEditorSource = 3,
|
||||
};
|
||||
FileType file_type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user