Version
3DF v.2X.XX
Language
C++
Description:
Below is sample code on how to encrypt your hsf file so that only your application can import hsf file.
You can use PartViewer to test sample.
#include "HStream.h" class encyrptHSF : public BBaseOpcodeHandler { public: encyrptHSF() : BBaseOpcodeHandler(0xB0) { }; ~encyrptHSF() {}; TK_Status Interpret(BStreamFileToolkit &, ID_Key, int) { return TK_Normal; }; TK_Status Execute (BStreamFileToolkit &) { return TK_Normal; }; TK_Status Read (BStreamFileToolkit & tk) { TK_Status status = TK_Normal; switch (m_stage) { case 0: { unsigned char bytes[13]; if ((status = GetData (tk, bytes, 13)) != TK_Normal) return status; m_stage = -1; } break; default: return tk.Error(); } return TK_Normal; }; TK_Status Write (BStreamFileToolkit & tk) { TK_Status status = TK_Normal; switch (m_stage) { case 0: { if ((status = PutOpcode (tk)) != TK_Normal) return status; m_stage++; } //nobreak; case 1: { unsigned char bytes[13] = {0, ')', '(', 0x7F, 0, ';', ' ', 'H', 'S', 'F', ' ', '1', '3'}; if ((status = PutData (tk, bytes, 13)) != TK_Normal) return status; m_stage = -1; } break; default: return tk.Error(); } return TK_Normal; }; }; static char const * filename = "D:/encyrptHSFed.hsf"; // Export void CSolidHoopsView::OnExtraSlot1() { HStreamFileToolkit tk; tk.SetPrewalkHandler (new encyrptHSF); HC_Open_Segment_By_Key (m_pHView->GetModelKey()); HTK_Write_Stream_File (filename, &tk); HC_Close_Segment (); } // Import void CSolidHoopsView::OnExtraSlot2() { HStreamFileToolkit tk; tk.SetOpcodeHandler (0xB0, new encyrptHSF); HC_Open_Segment_By_Key (m_pHView->GetModelKey()); HTK_Read_Stream_File (filename, &tk); HC_Close_Segment (); m_pHView->FitWorld(); m_pHView->Update(); }