Skip to content

Commit

Permalink
toolbox: allow shared dir to be set by user.
Browse files Browse the repository at this point in the history
  • Loading branch information
erichelgeson committed Oct 7, 2023
1 parent 1a8785c commit 9c65c85
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/BlueSCSI_Toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "BlueSCSI_disk.h"
#include "BlueSCSI_cdrom.h"
#include "BlueSCSI_log.h"
#include "BlueSCSI_config.h"
#include <minIni.h>
#include <SdFat.h>
extern "C" {
Expand Down Expand Up @@ -177,14 +178,14 @@ void onSetNextCD(const char * img_dir)
}

File gFile; // global so we can keep it open while transfering.
void onGetFile10(void) {
void onGetFile10(char * dir_name) {
uint8_t index = scsiDev.cdb[1];

uint32_t offset = ((uint32_t)scsiDev.cdb[2] << 24) | ((uint32_t)scsiDev.cdb[3] << 16) | ((uint32_t)scsiDev.cdb[4] << 8) | scsiDev.cdb[5];

if (offset == 0) // first time, open the file.
{
gFile = get_file_from_index(index, "/shared");
gFile = get_file_from_index(index, dir_name);
if(!gFile.isDirectory() && !gFile.isReadable())
{
scsiDev.status = CHECK_CONDITION;
Expand All @@ -211,7 +212,7 @@ void onGetFile10(void) {
Prepares a file for receving. The file name is null terminated in the scsi data.
*/
File receveFile;
void onSendFilePrep(void)
void onSendFilePrep(char * dir_name)
{
char file_name[32+1];
memset(file_name, '\0', 32+1);
Expand All @@ -220,7 +221,7 @@ void onSendFilePrep(void)
{
file_name[i] = scsiReadByte();
}
SD.chdir("/shared");
SD.chdir(dir_name);
receveFile.open(file_name, FILE_WRITE);
SD.chdir("/");
if(receveFile.isOpen() && receveFile.isWritable())
Expand Down Expand Up @@ -304,22 +305,29 @@ extern "C" int scsiBlueSCSIToolboxCommand()
image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
uint8_t command = scsiDev.cdb[0];

if (unlikely(command == BLUESCSI_TOOLBOX_COUNT_FILES))
if (unlikely(command == BLUESCSI_TOOLBOX_COUNT_FILES))
{
doCountFiles("/shared");
char img_dir[MAX_FILE_PATH];
getToolBoxSharedDir(img_dir);
doCountFiles(img_dir);
}
else if (unlikely(command == BLUESCSI_TOOLBOX_LIST_FILES))
{
// TODO: Allow user to set dir name via ini
onListFiles("/shared");
char img_dir[MAX_FILE_PATH];
getToolBoxSharedDir(img_dir);
onListFiles(img_dir);
}
else if (unlikely(command == BLUESCSI_TOOLBOX_GET_FILE))
{
onGetFile10();
char img_dir[MAX_FILE_PATH];
getToolBoxSharedDir(img_dir);
onGetFile10(img_dir);
}
else if (unlikely(command == BLUESCSI_TOOLBOX_SEND_FILE_PREP))
{
onSendFilePrep();
char img_dir[MAX_FILE_PATH];
getToolBoxSharedDir(img_dir);
onSendFilePrep(img_dir);
}
else if (unlikely(command == BLUESCSI_TOOLBOX_SEND_FILE_10))
{
Expand Down
5 changes: 5 additions & 0 deletions src/BlueSCSI_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ int getImg(int scsiId, int img_index, char* filename)

int dirlen = ini_gets(section, key, "", filename, sizeof(filename), CONFIGFILE);
return dirlen;
}

int getToolBoxSharedDir(char * dir_name)
{
return ini_gets("SCSI", "ToolBoxSharedDir", "/shared", dir_name, MAX_FILE_PATH, CONFIGFILE);
}
4 changes: 3 additions & 1 deletion src/BlueSCSI_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ int getBlockSize(char *filename, int scsiId, int default_size);

int getImgDir(int scsiId, char* dirname);

int getImg(int scsiId, int img_index, char* filename);
int getImg(int scsiId, int img_index, char* filename);

int getToolBoxSharedDir(char * dir_name);

0 comments on commit 9c65c85

Please sign in to comment.