|  | @@ -218,21 +218,39 @@ static void formatDriveInfoField(char *field, int fieldsize, bool align_right)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // remove path and extension from filename
 | 
	
		
			
				|  |  | -const char* get_image_name(const char* filename)
 | 
	
		
			
				|  |  | -{
 | 
	
		
			
				|  |  | -    char *j, *r;
 | 
	
		
			
				|  |  | +void extractFileName(const char* path, char* output) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    const char *lastSlash, *lastDot;
 | 
	
		
			
				|  |  | +    int fileNameLength;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    lastSlash = strrchr(path, '/');
 | 
	
		
			
				|  |  | +    if (!lastSlash) lastSlash = path;
 | 
	
		
			
				|  |  | +        else lastSlash++;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    lastDot = strrchr(lastSlash, '.');
 | 
	
		
			
				|  |  | +    if (lastDot && (lastDot > lastSlash)) {
 | 
	
		
			
				|  |  | +        fileNameLength = lastDot - lastSlash;
 | 
	
		
			
				|  |  | +        strncpy(output, lastSlash, fileNameLength);
 | 
	
		
			
				|  |  | +        output[fileNameLength] = '\0';
 | 
	
		
			
				|  |  | +    } else {
 | 
	
		
			
				|  |  | +        strcpy(output, lastSlash);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    r = (char *)malloc(strlen(filename));
 | 
	
		
			
				|  |  | -    strcpy(r, strrchr(filename,'/') + 5);
 | 
	
		
			
				|  |  | -    j = strrchr(r, '.');
 | 
	
		
			
				|  |  | -    *j = '\0';
 | 
	
		
			
				|  |  | +void setNameFromImage(image_config_t &img, const char *filename) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -   return r;
 | 
	
		
			
				|  |  | +    char image_name[MAX_FILE_PATH];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    extractFileName(filename, image_name);
 | 
	
		
			
				|  |  | +    memset(img.vendor, 0, 8);
 | 
	
		
			
				|  |  | +    strncpy(img.vendor, image_name, 8);
 | 
	
		
			
				|  |  | +    memset(img.prodId, 0, 8);
 | 
	
		
			
				|  |  | +    strncpy(img.prodId, image_name+8, 8);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // Set default drive vendor / product info after the image file
 | 
	
		
			
				|  |  |  // is loaded and the device type is known.
 | 
	
		
			
				|  |  | -static void setDefaultDriveInfo(int target_idx, const char* filename)
 | 
	
		
			
				|  |  | +static void setDefaultDriveInfo(int target_idx)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      image_config_t &img = g_DiskImages[target_idx];
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -250,8 +268,6 @@ static void setDefaultDriveInfo(int target_idx, const char* filename)
 | 
	
		
			
				|  |  |      static const char *apl_driveinfo_magopt[4]    = APPLE_DRIVEINFO_MAGOPT;
 | 
	
		
			
				|  |  |      static const char *apl_driveinfo_tape[4]      = APPLE_DRIVEINFO_TAPE;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    static const char *image_name;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      const char **driveinfo = NULL;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if (img.quirks == S2S_CFG_QUIRKS_APPLE)
 | 
	
	
		
			
				|  | @@ -283,28 +299,16 @@ static void setDefaultDriveInfo(int target_idx, const char* filename)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    if (img.quirks == S2S_CFG_QUIRKS_EMU)
 | 
	
		
			
				|  |  | +    if (img.vendor[0] == '\0')
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -            image_name = get_image_name(filename);
 | 
	
		
			
				|  |  | -            memset(img.vendor, 0, 8);
 | 
	
		
			
				|  |  | -            strncpy(img.vendor, image_name, 8);
 | 
	
		
			
				|  |  | -            memset(img.prodId, 0, 8);
 | 
	
		
			
				|  |  | -            strncpy(img.prodId, image_name+8, 8);
 | 
	
		
			
				|  |  | +        memset(img.vendor, 0, sizeof(img.vendor));
 | 
	
		
			
				|  |  | +        strncpy(img.vendor, driveinfo[0], sizeof(img.vendor));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    else
 | 
	
		
			
				|  |  | +    if (img.prodId[0] == '\0')
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        if (img.vendor[0] == '\0')
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            memset(img.vendor, 0, sizeof(img.vendor));
 | 
	
		
			
				|  |  | -            strncpy(img.vendor, driveinfo[0], sizeof(img.vendor));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (img.prodId[0] == '\0')
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            memset(img.prodId, 0, sizeof(img.prodId));
 | 
	
		
			
				|  |  | -            strncpy(img.prodId, driveinfo[1], sizeof(img.prodId));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        memset(img.prodId, 0, sizeof(img.prodId));
 | 
	
		
			
				|  |  | +        strncpy(img.prodId, driveinfo[1], sizeof(img.prodId));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if (img.revision[0] == '\0')
 | 
	
	
		
			
				|  | @@ -417,8 +421,13 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              debuglog("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        if (img.name_from_image)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            setNameFromImage(img, filename);
 | 
	
		
			
				|  |  | +            log("Vendor / product id set from image file name");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        setDefaultDriveInfo(target_idx, filename);
 | 
	
		
			
				|  |  | +        setDefaultDriveInfo(target_idx);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #ifdef PLATFORM_CONFIG_HOOK
 | 
	
		
			
				|  |  |          PLATFORM_CONFIG_HOOK(&img);
 | 
	
	
		
			
				|  | @@ -552,6 +561,7 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
 | 
	
		
			
				|  |  |      img.bytesPerSector = ini_getl(section, "BlockSize", img.bytesPerSector, CONFIGFILE);
 | 
	
		
			
				|  |  |      img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
 | 
	
		
			
				|  |  |      img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", 0, CONFIGFILE);
 | 
	
		
			
				|  |  | +    img.name_from_image = ini_getbool(section, "NameFromImage", 0, CONFIGFILE);
 | 
	
		
			
				|  |  |      img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
 | 
	
		
			
				|  |  |      img.reinsert_on_inquiry = ini_getbool(section, "ReinsertCDOnInquiry", img.reinsert_on_inquiry, CONFIGFILE);
 | 
	
		
			
				|  |  |      img.reinsert_after_eject = ini_getbool(section, "ReinsertAfterEject", img.reinsert_after_eject, CONFIGFILE);
 |