Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

OutputBlocks.cpp

#include "whiptk\whip_toolkit.h"
#include <stdio.h>
#include <io.h>

WT_Result OutputBlocks(const char* sFilename, int nFormat)
{
    WT_File input_file;
    input_file.set_filename(sFilename);
    input_file.set_file_mode(WT_File::Block_Read);
    WD_CHECK( input_file.open() );

    WT_Directory directory;
    directory = input_file.get_directory();

    int BlockCount = 0;

    if (!directory.is_empty()) 
    {
        WT_BlockRef *current = (WT_BlockRef *) directory.get_head();

        while (current != WD_Null)
        {
            char tmp_buf[1024], tmp_buf1[1024];
            ZeroMemory((void *) &tmp_buf, 1024);

            WT_BlockRef new_item(*current);
            WT_File tmp_file_object;
            tmp_file_object.set_filename("TEMP");

            WD_CHECK( input_file.read_block(tmp_file_object, new_item) );        

            WT_String outputfile = input_file.filename();
            strcpy(tmp_buf, outputfile.ascii());
            if (strstr(tmp_buf, ".") != NULL)
                *strstr(tmp_buf, ".") = '\0';
            sprintf(tmp_buf, "%s_out%d.dwf", outputfile, BlockCount);
            if(!_access(tmp_buf,0)) 
            {
                if(!DeleteFile(tmp_buf)) 
                {
                    ZeroMemory((void *) &tmp_buf1, 1024);
                    printf(tmp_buf1, "%s file already exists.\\nUnable to delete it for overwriting!", tmp_buf);
                    return WT_Result::Internal_Error;
                }
            }
            if(!CopyFile("TEMP", tmp_buf, FALSE)) 
            {
                ZeroMemory((void *) &tmp_buf1, 1024);
                printf(tmp_buf1, "%s file already exists.\\nUnable to copy it for overwriting!", tmp_buf);
                return WT_Result::Internal_Error;
            }
            BlockCount++;
 
            current = (WT_BlockRef *) current->next();
        }
    }
    WD_CHECK( input_file.close() );
 
    return WT_Result::Success;
}

Generated on Mon May 9 23:16:54 2005 for Autodesk DWF Toolkit by  doxygen 1.4.1