WhipExamples/OutputBlocks.cpp

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #include "whiptk/whip_toolkit.h"
00023 #include <stdio.h>
00024 #include <io.h>
00025 #include "whiptk/w2d_class_factory.h"
00026 
00027 WT_Result OutputBlocks(const char* sFilename, int nFormat)
00028 {
00029     WT_W2D_Class_Factory cf;
00030     WT_File *input_file = cf.Create_File();
00031     if (input_file == NULL)
00032         return WT_Result::Out_Of_Memory_Error;
00033 
00034     input_file->set_filename(sFilename);
00035     input_file->set_file_mode(WT_File::Block_Read);
00036     WD_CHECK( input_file->open() );
00037 
00038     WT_Directory directory;
00039     directory = input_file->get_directory();
00040 
00041     int BlockCount = 0;
00042 
00043     if (!directory.is_empty()) 
00044     {
00045         WT_BlockRef *current = (WT_BlockRef *) directory.get_head();
00046 
00047         while (current != WD_Null)
00048         {
00049             wchar_t tmp_buf[1024], tmp_buf1[1024];
00050             ZeroMemory((void *) &tmp_buf, 1024*sizeof(wchar_t));
00051 
00052             WT_BlockRef new_item(*current);
00053             WT_File *tmp_file_object = cf.Create_File();
00054             if (tmp_file_object == NULL)
00055                 return WT_Result::Out_Of_Memory_Error;
00056             tmp_file_object->set_filename("TEMP");
00057 
00058             WD_CHECK( input_file->read_block(*tmp_file_object, new_item) );        
00059 
00060             WT_String outputfile = input_file->filename();
00061             wchar_t *pStr = WT_String::to_wchar( outputfile.length(), outputfile );
00062             wcscpy(tmp_buf, pStr);
00063             delete[] pStr;
00064             if (wcsstr(tmp_buf, L".") != NULL)
00065                 *wcsstr(tmp_buf, L".") = '\0';
00066             swprintf(tmp_buf, L"%s_out%d.dwf", outputfile, BlockCount);
00067             if(!_waccess(tmp_buf,0)) 
00068             {
00069                 if(!DeleteFile(tmp_buf)) 
00070                 {
00071                     ZeroMemory((void *) &tmp_buf1, 1024*sizeof(wchar_t));
00072                     swprintf(tmp_buf1, L"%s file already exists.\\nUnable to delete it for overwriting!", tmp_buf);
00073                     return WT_Result::Internal_Error;
00074                 }
00075             }
00076             if(!CopyFile(L"TEMP", tmp_buf, FALSE)) 
00077             {
00078                 ZeroMemory((void *) &tmp_buf1, 1024);
00079                 swprintf(tmp_buf1, L"%s file already exists.\\nUnable to copy it for overwriting!", tmp_buf);
00080                 return WT_Result::Internal_Error;
00081             }
00082             BlockCount++;
00083  
00084             current = (WT_BlockRef *) current->next();
00085             cf.Destroy( tmp_file_object );
00086         }
00087     }
00088     WD_CHECK( input_file->close() );
00089     
00090     cf.Destroy( input_file );
00091  
00092     return WT_Result::Success;
00093 }

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5