First post, by ErikGG
- Rank
- Member
Hi all,
Recently I've gotten a few questions from the community about the subject on long and short names and that D.O.G. generates them incorrectly.
I could just block off longnames, but difficult problems are most of the time the most interresting to solve, thus I'm now browsing through the DOSBox source for an answer on how DOSBox does the whole conversion thing to Windows.
I ended up on the routine DOS_FCB::GetName in the dos_classes.cpp. But this seems to be only a copy routine.
Currently I have a routine that kind of mimics a long to short routine but it doesn't check for existing files, it just cuts if needed to account for the 8.3 rule and only adds ~1 each time.
My question now is how does DOSBox sort the ~1, ~2, ... witch file gets what short name. Does it do it alphabetically or some other way?
For the people interrested here is my code in Delphi :
function GetShortName(sLongName: string): string;
var
sShortName: string;
nShortNameLen: Integer;
Pos : Integer;
TmpName,
TmpStr : String;
TmpExt : String;
begin
Result := '';
TmpName := sLongName;
Pos := System.Pos('\', TmpName);
//Cut every directoryname down to 8 characters.
while Pos <> 0 do
Begin
TmpStr := Copy(TmpName,1, Pos-1);
TmpName := Copy(TmpName,Pos+1, Length(TmpName));
if Length(TmpStr) > 8 then
Begin
TmpStr := ANSIReplaceText(TmpStr, ' ', '');
TmpStr := Copy(TmpStr, 1, 6) + '~1';
end;
Result := Result + TmpStr + '\';
Pos := System.Pos('\', TmpName);
end;
if Length(TmpName) <> 0 then//Contains a filename
Begin
TmpExt := ExtractFileExt(TmpName);
TmpName := ChangeFileExt(TmpName, '');
if Length(TmpExt) > 4 then//With the dot
Begin
TmpName := ANSIReplaceText(TmpName, ' ', '');
Result := Result + Copy(TmpName, 1, 6) + '~1';
Result := Result + Copy(TmpExt, 1, 4);
end
else
Begin
if Length(TmpName) > 8 then
Begin
TmpName := ANSIReplaceText(TmpName, ' ', '');
Result := Result + Copy(TmpName, 1, 6) + '~1' + TmpExt;
end
else
Result := Result + TmpName + TmpExt;
end;
end;
end;
Thanks for the help,
Erik.