VOGONS


First post, by ErikGG

User metadata
Rank Member
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.

Reply 1 of 3, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

there is a windows code that does that for you (I think) but windows seems to reverse the files compared to DOSBox

(so 12345678a.exe and 12345678b.exe would become 123456~1 ~2 in dosbox and ~2 ~1 in windows)

Our code can be found in src/dos/drive_cache.cpp

Water flows down the stream
How to ask questions the smart way!

Reply 2 of 3, by ErikGG

User metadata
Rank Member
Rank
Member

Thanks QBix,

The Windows API you mentioned is GetShortPathName.
That one I currently use, but as DOSBox is the platform I'm building on, I need to do it correctly.

Will have a look.

Thanks for the fast reply.

Erik.

Reply 3 of 3, by ErikGG

User metadata
Rank Member
Rank
Member

Just to let you all know,

I think I learned my D.O.G. a new trick, generate correct short filenames. A wopping 300 lines of code just for one function 😵 , but it is worth it.

Thanks again QBix for the directions. Took a little differant approach but it also does the trick.

Erik.