1
0
Fork 0

Don't remove bytes from autoexec.bat when changing settings from autoexec.bat, but replace them instead. This way the location stays valid.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4212
This commit is contained in:
Peter Veenstra 2019-04-20 13:55:35 +00:00
parent eb26b9a58e
commit bec0e79890

View file

@ -125,21 +125,29 @@ AutoexecObject::~AutoexecObject(){
// Remove the line from the autoexecbuffer and update environment
for(auto_it it = autoexec_strings.begin(); it != autoexec_strings.end(); ) {
if((*it) == buf) {
it = autoexec_strings.erase(it);
if ((*it) == buf) {
std::string::size_type n = buf.size();
char* buf2 = new char[n + 1];
safe_strncpy(buf2, buf.c_str(), n + 1);
bool stringset = false;
// If it's a environment variable remove it from there as well
if((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){
if ((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){
char* after_set = buf2 + 4;//move to variable that is being set
char* test = strpbrk(after_set,"=");
if(!test) continue;
if (!test) continue;
*test = 0;
stringset = true;
//If the shell is running/exists update the environment
if(first_shell) first_shell->SetEnv(after_set,"");
if (first_shell) first_shell->SetEnv(after_set,"");
}
delete [] buf2;
if (stringset && first_shell && first_shell->bf && first_shell->bf->filename.find("AUTOEXEC.BAT") != std::string::npos) {
//Replace entry with spaces if it is a set and from autoexec.bat, as else the location counter will be off.
*it = buf.assign(buf.size(),' ');
it++;
} else {
it = autoexec_strings.erase(it);
}
} else it++;
}
this->CreateAutoexec();