Example #1
0
bool WdeSaveResource( WdeResInfo *res_info, bool get_name )
{
    WdeGetFileStruct    gf;
    char                *filter;
    char                *fn;
    int                 fn_offset;
    bool                got_name;
    bool                ok;
    OBJPTR              main_obj;

    fn_offset = 0;
    got_name = FALSE;

    ok = (res_info != NULL && res_info->info != NULL);

    if( ok ) {
        if( res_info->info->save_name != NULL ) {
            fn = res_info->info->save_name;
        } else {
            res_info->info->save_type = res_info->info->file_type;
            fn = WdeStrDup( res_info->info->file_name );
            got_name = TRUE;
        }

        if( get_name || fn == NULL || *fn == '\0' ) {
            filter = WdeSelectSaveFilter( res_info->info->file_type );
            gf.file_name = fn;
            gf.title = WdeResSaveTitle;
            gf.filter = filter;
            fn = WdeGetSaveFileName( &gf );
            got_name = TRUE;
            res_info->info->save_type = WR_DONT_KNOW;
        }

        ok = (fn != NULL && *fn != '\0');
    }

    if( ok ) {
        if( got_name && res_info->info->save_name != NULL ) {
            WRMemFree( res_info->info->save_name );
        }
        res_info->info->save_name = fn;
        if( res_info->info->save_type == WR_DONT_KNOW ) {
            res_info->info->save_type = WdeSelectFileType( fn, res_info->is32bit );
        }
        ok = (res_info->info->save_type != WR_DONT_KNOW);
    }

    if( ok ) {
        if( WdeIsHashTableDirty( res_info->hash_table ) &&
                !WdeIsHashSaveRejectedSet( res_info->hash_table ) ) {
            if( res_info->sym_name == NULL ) {
                res_info->sym_name = WdeCreateSymName( fn );
            }
        }
    }

    if( ok ) {
        if( WdeIsHashTableDirty( res_info->hash_table ) ) {
            if( (main_obj = GetMainObject()) != NULL ) {
                Forward( main_obj, RESOLVE_HELPSYMBOL, &ok, NULL ); /* JPK */
                Forward( main_obj, RESOLVE_SYMBOL, &ok, NULL );
            }
        }
        WdeCreateDLGInclude( res_info, res_info->sym_name );
        ok = WdeSaveResourceToFile( res_info );
        if( !ok ) {
            WdeDisplayErrorMsg( WDE_SAVEFAILED );
        }
    }

    if( ok ) {
        if( WdeIsHashTableDirty( res_info->hash_table ) &&
                !WdeIsHashSaveRejectedSet( res_info->hash_table ) ) {
            WdeWriteSymbols( res_info->hash_table, &res_info->sym_name, get_name );
        }
    }

    if( ok ) {
        //fn_offset = WRFindFnOffset( fn );
        SendMessage( res_info->res_win, WM_SETTEXT, 0, (LPARAM)(LPVOID)&fn[fn_offset] );
    }

    return( ok );
}
Example #2
0
bool WdeSaveObjectAs( WdeResInfo *rinfo, WdeDialogBoxInfo *dbi,
                      char **file_name, WResID *name, void *rdata, uint_32 size,
                      WResLangType *lang, bool get_name )
{
    char                *fname;
    WRFileType          ftype;
    WdeGetFileStruct    gf;
    WRSaveIntoData      idata;
    WdeResDlgItem       ditem;
    bool                is_rc;
    bool                ok;

    fname = NULL;
    idata.type = NULL;

    ok = (rinfo != NULL && dbi != NULL && file_name != NULL &&
          name != NULL && rdata != NULL);

    if( ok ) {
        if( get_name || *file_name == NULL ) {
            gf.file_name = *file_name;
            gf.title = WdeDlgSaveTitle;
            if( get_name ) {
                gf.title = WdeDlgSaveAsTitle;
            }
            gf.filter = WdeResSaveFilter;
            fname = WdeGetSaveFileName( &gf );
        } else {
            fname = WdeStrDup( *file_name );
        }
        ok = (fname != NULL && *fname != '\0');
    }

    if( ok ) {
        ftype = WdeSelectFileType( fname, rinfo->is32bit );
        ok = (ftype != WR_DONT_KNOW);
    }

    if( ok ) {
        is_rc = WdeIsFileAnRCFile( fname );
        ok = ((idata.type = WResIDFromNum( RESOURCE2INT( RT_DIALOG ) )) != NULL);
    }

    if( ok ) {
        memset( &ditem, 0, sizeof( WdeResDlgItem ) );
        ditem.dialog_info = dbi;
        ditem.dialog_name = name;
        if( is_rc ) {
            ok = WdeSaveObjectToRC( fname, rinfo, &ditem, FALSE );
        }
    }

    // if we are saving a .RES file then auto create a dlg script
    if( ok ) {
        if( ftype == WR_WIN16M_RES || ftype == WR_WIN16W_RES ||
            ftype == WR_WINNTM_RES || ftype == WR_WINNTW_RES ) {
            char        dlgName[_MAX_PATH];
            if( WdeCreateDLGName( fname, dlgName ) ) {
                ok = WdeSaveObjectToRC( dlgName, rinfo, &ditem, FALSE );
            }
        }
    }

    if( ok ) {
        idata.next = NULL;
        idata.name = name;
        idata.data = rdata;
        idata.lang = *lang;
        idata.size = size;
        idata.MemFlags = dbi->MemoryFlags;
        ok = WRSaveObjectAs( fname, ftype, &idata );
    }

    if( idata.type != NULL ) {
        WResIDFree( idata.type );
    }

    if( ok ) {
        if( fname != NULL ) {
            if( *file_name != NULL ) {
                WRMemFree( *file_name );
            }
            *file_name = fname;
        }
    } else {
        if( fname != NULL ) {
            WRMemFree( fname );
        }
    }

    return( ok );
}