Aller au contenu

Photo

model type identification question


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Tarot Redhand

Tarot Redhand
  • Members
  • 2 674 messages

I have written a small utility that operates on uncompiled (ASCII) models only. What I would like to be able to do is to make the program test if the model does indeed contain uncompiled data. So far the only idea I've been able to come up with is to check the length of the first line of data and if it's greater than an arbitrary value to reject the file.

 

Obviously this approach is fraught with potential problems. Is there a better test I can perform in code that will detect all compiled models? 

 

Thanks in advance.

 

TR



#2
OldTimeRadio

OldTimeRadio
  • Members
  • 1 400 messages

I don't know exactly what resources you have to make that test.  For instance, the binary model format page indicates that if the first 4 bytes of a file are all zeros, it's likely not an ASCII file and can then be assumed to be a binary one.  If you're looking for a string, I'd say look for "endnode", "newmodel" or something like that?  Those strings aren't going to appear in binary files and, off the top of my head, I think they'll always appear in ASCII ones.


  • Tarot Redhand, Michael DarkAngel et TheOneBlackRider aiment ceci

#3
Tarot Redhand

Tarot Redhand
  • Members
  • 2 674 messages

Thanks OTR. It's written in vb 2008 which has access to the .net framework 3.5 which means that I have access to the Left() function. That function returns the first x number of characters in a string that you specify. I'll try that 4 nuls test and hope for the best. Fortunately the standard open file dialogue has a setting that will not allow the names of non-existant files to be returned, so that one is covered.

 

Thanks again.

 

TR



#4
Michael DarkAngel

Michael DarkAngel
  • Members
  • 368 messages


Thanks OTR. It's written in vb 2008 which has access to the .net framework 3.5 which means that I have access to the Left() function. That function returns the first x number of characters in a string that you specify. I'll try that 4 nuls test and hope for the best. Fortunately the standard open file dialogue has a setting that will not allow the names of non-existant files to be returned, so that one is covered.

 

Thanks again.

 

TR

 

Doing it that way will not return what you are looking for.  If you are going to do it with string comparisons you would have better luck looking at the first character of the first line.  If that returns "#", it is most likely an ascii file.  If it crashes or returns an error, it is most likely a binary file.

 

A better way that should not crash would be to use BinaryReader Class and FileStream Class.  Open the file using those two classes, then using ReadInt32 Method will read the first four bytes.  If that value is zero, you have a binary file.

 

icon_zdevil.gif

MDA


  • OldTimeRadio et TheOneBlackRider aiment ceci

#5
Tarot Redhand

Tarot Redhand
  • Members
  • 2 674 messages

Purely for efficiency I used the following (edited for relevance) code that uses standard traditional vb stuff -

Dim intTestWord As Integer = &HFFFF
 
REM <cut...>
 
FileOpen(1, sFileName, OpenMode.Binary)
FileGet(1, intTestWord)
FileClose(1)
If intTestWord = 0 Then
    MsgBox("Sorry, this program only works with uncompiled models" & Chr(13) & Chr(10) & "and that file appears to be compiled!", MsgBoxStyle.Exclamation)
    Return
End If

This appears to work. BTW in VB2008 an integer is 32 bits. Back to writing the manual...

 

TR


  • Michael DarkAngel aime ceci