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;varsShortName: string;nShortNameLen: Integer;Pos : Integer;TmpName,TmpStr : String;TmpExt : String;beginResult := '';TmpName := sLongName;Pos := System.Pos('\', TmpName);//Cut every directoryname down to 8 characters.while Pos <> 0 doBeginTmpStr := Copy(TmpName,1, Pos-1);TmpName := Copy(TmpName,Pos+1, Length(TmpName));if Length(TmpStr) > 8 thenBeginTmpStr := ANSIReplaceText(TmpStr, ' ', '');TmpStr := Copy(TmpStr, 1, 6) + '~1';end;Result := Result + TmpStr + '\';Pos := System.Pos('\', TmpName);end;if Length(TmpName) <> 0 then//Contains a filenameBeginTmpExt := ExtractFileExt(TmpName);TmpName := ChangeFileExt(TmpName, '');if Length(TmpExt) > 4 then//With the dotBeginTmpName := ANSIReplaceText(TmpName, ' ', '');Result := Result + Copy(TmpName, 1, 6) + '~1';Result := Result + Copy(TmpExt, 1, 4);endelseBeginif Length(TmpName) > 8 thenBeginTmpName := ANSIReplaceText(TmpName, ' ', '');Result := Result + Copy(TmpName, 1, 6) + '~1' + TmpExt;endelseResult := Result + TmpName + TmpExt;end;end;end;
Thanks for the help,
Erik.