Skip to content
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

1500 add physical cd drive support #1609

Merged
merged 31 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f33887f
feat: Add physical CD drive support in the GUI
midwan Nov 13, 2024
1feb58c
refactor: fix cdrom device names
midwan Nov 13, 2024
72507c2
refactor: remove unnecessary type change
midwan Nov 13, 2024
1aa52e6
refactor: store rootdir for CD devices in Amiberry
midwan Nov 13, 2024
d6fab36
feat: auto-detect and list physical cd drives in dropdowns
midwan Nov 14, 2024
a438cc3
refactor: added cdfs automount cd drives option in GUI
midwan Nov 14, 2024
e17794c
refactor: remove cd lists from dropdowns
midwan Nov 14, 2024
d365ada
refactor: minor optimizations in amiberry_filesys
midwan Nov 14, 2024
317d312
fixed build
midwan Nov 14, 2024
9ff49ba
feat: added blkdev_ioctl
midwan Nov 15, 2024
9a41642
Squashed commit of the following:
midwan Nov 16, 2024
56dc56a
Disable this for macOS for now
midwan Nov 16, 2024
9be4a72
better separation for macOS
midwan Nov 16, 2024
79ee7e5
Add device options in dropdowns.
midwan Nov 16, 2024
e420a8a
refactor sys_cddev_open
midwan Nov 16, 2024
22d02f0
refactor: improve IOCTL device detection
midwan Nov 16, 2024
317c385
silence some log entries that are making too much noise
midwan Nov 16, 2024
f286499
refactor: fetch geometry
midwan Nov 16, 2024
24190ae
refactor: remove no-op functions
midwan Nov 16, 2024
24e4725
refactor: close and re-open file handle when opening
midwan Nov 16, 2024
fe82bb1
Squashed commit of the following:
midwan Nov 23, 2024
261719b
Merge branch 'master' into 1500-add-physical-cd-drive-support
midwan Nov 25, 2024
618d72f
Merge branch 'master' into 1500-add-physical-cd-drive-support
midwan Nov 25, 2024
cc3d3a7
refactor: revert vbi changes #1515
midwan Nov 24, 2024
c2eeb04
Merge branch 'master' into 1500-add-physical-cd-drive-support
midwan Dec 5, 2024
1785c5e
Merge branch 'master' into 1500-add-physical-cd-drive-support
midwan Jan 6, 2025
1ce4f76
Fixes after merge
midwan Jan 6, 2025
8fd2ff4
refactor: use const in more places
midwan Jan 6, 2025
6e988f2
Merge branch 'master' into 1500-add-physical-cd-drive-support
midwan Jan 23, 2025
c0db52f
refactor: cdda_play should be int
midwan Jan 23, 2025
d6421ca
refactor: bring back PanelHDD changes after merge
midwan Jan 23, 2025
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
2 changes: 2 additions & 0 deletions cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(SOURCE_FILES
src/osdep/amiberry_serial.cpp
src/osdep/amiberry_uaenet.cpp
src/osdep/amiberry_whdbooter.cpp
src/osdep/blkdev_ioctl.cpp
src/osdep/ioport.cpp
src/osdep/sigsegv_handler.cpp
src/osdep/socket.cpp
Expand Down Expand Up @@ -331,6 +332,7 @@ set(SOURCE_FILES
src/osdep/gui/SelectFolder.cpp
src/osdep/gui/SelectFile.cpp
src/osdep/gui/CreateFilesysHardfile.cpp
src/osdep/gui/EditCDDrive.cpp
src/osdep/gui/EditFilesysVirtual.cpp
src/osdep/gui/EditFilesysHardfile.cpp
src/osdep/gui/EditFilesysHardDrive.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/blkdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ void blkdev_fix_prefs (struct uae_prefs *p)
continue;
if (p->cdslots[i].inuse || p->cdslots[i].name[0]) {
TCHAR *name = p->cdslots[i].name;
#ifdef _WIN32
if (_tcslen (name) == 3 && name[1] == ':' && name[2] == '\\') {
#else
if (name[0] == '/' && name[1] == 'd' && name[2] == 'e' && name[3] == 'v' && name[4] == '/') {
#endif
if (currprefs.scsi && (currprefs.uaescsimode == UAESCSI_SPTI || currprefs.uaescsimode == UAESCSI_SPTISCAN))
cdscsidevicetype[i] = SCSI_UNIT_SPTI;
else
Expand Down
4 changes: 4 additions & 0 deletions src/expansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,10 @@ static uaecptr check_boot_rom (struct uae_prefs *p, int *boot_rom_type)
#ifdef WIN32
if (p->win32_automount_drives || p->win32_automount_cddrives || p->win32_automount_netdrives || p->win32_automount_removable)
return b;
#endif
#ifdef AMIBERRY
if (p->automount_cddrives || p->automount_removable)
return b;
#endif
if (p->socket_emu)
return b;
Expand Down
6 changes: 5 additions & 1 deletion src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,11 @@ static int set_filesys_unit (int nr, struct uaedev_config_info *ci, bool custom)
return ret;
}

static int add_filesys_unit (struct uaedev_config_info *ci, bool custom)
// we want to reference this from amiberry_filesys.cpp also
#ifndef AMIBERRY
static
#endif
int add_filesys_unit (struct uaedev_config_info *ci, bool custom)
{
int nr;

Expand Down
4 changes: 4 additions & 0 deletions src/include/uae.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@ extern void uaerandomizeseed(void);

int get_guid_target (uae_u8 *out);
void filesys_addexternals (void);
#ifdef AMIBERRY
extern std::vector<std::string> get_cd_drives();
extern int add_filesys_unit(struct uaedev_config_info* ci, bool custom);
#endif

#endif /* UAE_UAE_H */
21 changes: 20 additions & 1 deletion src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,25 @@ void read_controller_mapping_from_file(controller_mapping& input, const std::str
in_file.close();
}

std::vector<std::string> get_cd_drives()
{
char path[MAX_DPATH];
std::vector<std::string> results{};

FILE* fp = popen("lsblk -o NAME,TYPE | grep 'rom' | awk '{print \"/dev/\" $1}'", "r");
if (fp == nullptr) {
write_log("Failed to run 'lsblk' command, cannot auto-detect CD drives in system\n");
return results;
}

while (fgets(path, sizeof(path), fp) != nullptr) {
path[strcspn(path, "\n")] = 0;
results.emplace_back(path);
}
pclose(fp);
return results;
}

void target_setdefaultstatefilename(const TCHAR* name)
{
TCHAR path[MAX_DPATH];
Expand Down Expand Up @@ -4932,4 +4951,4 @@ void target_setdefaultstatefilename(const TCHAR* name)
}
}
_tcscpy(savestate_fname, path);
}
}
42 changes: 30 additions & 12 deletions src/osdep/amiberry_filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "filesys.h"
#include "zfile.h"
#include <unistd.h>
#include <algorithm>
#include <list>
#include <dirent.h>
#include <iconv.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ void utf8_to_latin1_string(std::string& input, std::string& output)
std::string dst;

auto* iconv_ = iconv_open("ISO-8859-1//TRANSLIT", "UTF-8");
if (iconv_ == (iconv_t)-1) {
if (iconv_ == iconv_t(-1)) {
if (!has_logged_iconv_fail) {
write_log("iconv_open failed: will be copying directory entries verbatim\n");
has_logged_iconv_fail = true;
Expand All @@ -61,7 +62,7 @@ void utf8_to_latin1_string(std::string& input, std::string& output)
char* dst_ptr = buf.data();
size_t dst_size = buf.size();
size_t res = ::iconv(iconv_, &src_ptr, &src_size, &dst_ptr, &dst_size);
if (res == (size_t)-1) {
if (res == size_t(-1)) {
if (errno != E2BIG) {
// skip character
++src_ptr;
Expand Down Expand Up @@ -142,7 +143,7 @@ std::string prefix_with_application_directory_path(std::string currentpath)
}


std::string prefix_with_data_path(std::string filename)
std::string prefix_with_data_path(const std::string& filename)
{
#ifdef __MACH__
CFBundleRef mainBundle = CFBundleGetMainBundle();
Expand Down Expand Up @@ -172,7 +173,7 @@ std::string prefix_with_data_path(std::string filename)
#endif
}

std::string prefix_with_whdboot_path(std::string filename)
std::string prefix_with_whdboot_path(const std::string& filename)
{
#ifdef __MACH__
CFBundleRef mainBundle = CFBundleGetMainBundle();
Expand Down Expand Up @@ -828,8 +829,7 @@ int my_issamevolume(const TCHAR* path1, const TCHAR* path2, TCHAR* path)
my_canonicalize_path(path2, p2, sizeof p2 / sizeof(TCHAR));

unsigned int len = _tcslen(p1);
if (len > _tcslen(p2))
len = _tcslen(p2);
len = std::min<size_t>(len, _tcslen(p2));

if (_tcsnicmp(p1, p2, len))
return 0;
Expand Down Expand Up @@ -895,18 +895,36 @@ int target_get_volume_name(struct uaedev_mount_info* mtinf, struct uaedev_config
bool copyfile(const char* target, const char* source, const bool replace)
{
#ifdef USE_OLDGCC
std::experimental::filesystem::copy_options options = {};
options = replace ? experimental::filesystem::copy_options::overwrite_existing : experimental::filesystem::copy_options::none;
std::experimental::filesystem::copy_options options = replace
? experimental::filesystem::copy_options::overwrite_existing
: experimental::filesystem::copy_options::none;
#else
std::filesystem::copy_options options = {};
options = replace ? filesystem::copy_options::overwrite_existing : filesystem::copy_options::none;
std::filesystem::copy_options options = replace
? filesystem::copy_options::overwrite_existing
: filesystem::copy_options::none;
#endif
return copy_file(source, target, options);
}

void filesys_addexternals(void)
{
// this would mount system drives on Windows
if (!currprefs.automount_cddrives)
return;

const auto cd_drives = get_cd_drives();
if (!cd_drives.empty())
{
int drvnum = 0;
for (auto& drive : cd_drives)
{
struct uaedev_config_info ci = { 0 };
_tcscpy(ci.rootdir, drive.c_str());
ci.readonly = true;
ci.bootpri = -20 - drvnum;
add_filesys_unit(&ci, true);
drvnum++;
}
}
}

std::string my_get_sha1_of_file(const char* filepath)
Expand All @@ -916,7 +934,7 @@ std::string my_get_sha1_of_file(const char* filepath)
return "";
}

int fd = open(filepath, O_RDONLY);
const int fd = open(filepath, O_RDONLY);
if (fd < 0) {
write_log("my_get_sha1_of_file: open on file %s failed\n", filepath);
return "";
Expand Down
4 changes: 3 additions & 1 deletion src/osdep/amiberry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,6 @@ void CreateDefaultDevicename(char* name)
}
}


int tweakbootpri(int bp, int ab, int dnm)
{
if (dnm)
Expand Down Expand Up @@ -1601,6 +1600,9 @@ void new_cddrive(int entry)
ci.device_emu_unit = 0;
ci.controller_type = current_cddlg.ci.controller_type;
ci.controller_unit = current_cddlg.ci.controller_unit;
#ifdef AMIBERRY
_tcscpy(ci.rootdir, current_cddlg.ci.rootdir);
#endif
ci.type = UAEDEV_CD;
ci.readonly = true;
ci.blocksize = 2048;
Expand Down
Loading
Loading