Author Topic: model type identification question  (Read 480 times)

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
model type identification question
« on: January 11, 2016, 03:51:33 pm »


               

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



               
               

               
            

Legacy_OldTimeRadio

  • Hero Member
  • *****
  • Posts: 2307
  • Karma: +0/-0
model type identification question
« Reply #1 on: January 11, 2016, 04:31:18 pm »


               

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.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
model type identification question
« Reply #2 on: January 12, 2016, 12:11:04 am »


               

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



               
               

               
            

Legacy_Michael DarkAngel

  • Hero Member
  • *****
  • Posts: 627
  • Karma: +0/-0
model type identification question
« Reply #3 on: January 12, 2016, 02:48:54 am »


               




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



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
model type identification question
« Reply #4 on: January 12, 2016, 12:18:58 pm »


               

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