I have never compiled before, and I will leave it to you gurus.
But I want to drive this (single) program around the block, so any assistance would be appreciated.
I have:
WindowsXP Pro
Borland Compiler 5.5 (free version)
MS Visual C++ 2005 Express and the Platform SDK
I am able to compile example codes in both compilers, so I am relatively confident that they are installed correctly.
Here is the code:
// slice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <time.h>
#include <process.h>
#include <stdlib.h>
#include <malloc.h>
#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
#define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)),SWAPWORD(LOWORD(x)))
#define UUID_NULL "00000000-0000-0000-0000-000000000000"
#pragma pack(1)
char szTargetUUID[] = UUID_NULL;
typedef struct
{
DWORD dwOffset;
WORD wMagic;
WORD wFlags;
time_t ltTime;
BYTE bUUID[16];
WORD wType;
DWORD dwSize;
} CACHE_INDEX;
typedef struct
{
WORD wSize;
LPBYTE lpData;
} J2C_BLOCK;
int slice(char *lpszPathIndex, char *lpszPathData);
int main(int argc, char* argv[])
{
char szPathAppData[MAX_PATH];
char szPathSearch[MAX_PATH];
char szPathIndex[MAX_PATH];
char szPathData[MAX_PATH];
HANDLE hSearch;
WIN32_FIND_DATA wfdSearch;
if (argc > 1)
{
printf("Searching for UUID %s\n", argv[1]);
strncpy(szTargetUUID, argv[1], sizeof(szTargetUUID));
}
sprintf(szPathIndex, "c:\\program files\\secondlife\\app_settings\\static_index.db2");
sprintf(szPathData, "c:\\program files\\secondlife\\app_settings\\static_data.db2");
printf("Found index at %s\n", szPathIndex);
slice(szPathIndex, szPathData);
if (!GetEnvironmentVariable("APPDATA", szPathAppData, sizeof(szPathAppData)))
{
printf("Couldn't find application data folder path\n");
return -1;
}
sprintf(szPathSearch, "%s\\secondlife\\cache\\index.db2.x.*", szPathAppData);
hSearch = FindFirstFile(szPathSearch, &wfdSearch);
if (hSearch != INVALID_HANDLE_VALUE)
{
do
{
char *lpszSalt = NULL;
lpszSalt = strrchr(wfdSearch.cFileName, '.');
if (lpszSalt)
{
sprintf(szPathIndex, "%s\\secondlife\\cache\\index.db2.x%s", szPathAppData, lpszSalt);
sprintf(szPathData, "%s\\secondlife\\cache\\data.db2.x%s", szPathAppData, lpszSalt);
printf("Found index at %s\n", szPathIndex);
slice(szPathIndex, szPathData);
}
}
while (FindNextFile(hSearch, &wfdSearch));
FindClose(hSearch);
}
return 0;
}
int slice(char *lpszPathIndex, char *lpszPathData)
{
CACHE_INDEX index;
int nMode = 0;
int nImage = 0;
int nRead = 0;
FILE *fpIndex = NULL;
FILE *fpData = NULL;
FILE *fpWrite = NULL;
fpIndex = fopen(lpszPathIndex, "rb");
fpData = fopen(lpszPathData, "rb");
if (fpIndex && fpData)
{
while (nRead = fread(&index, 1, sizeof(CACHE_INDEX), fpIndex))
{
char szUUID[37];
_snprintf(szUUID, sizeof(szUUID),
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
index.bUUID[0], index.bUUID[1], index.bUUID[2], index.bUUID[3],
index.bUUID[4], index.bUUID[5], index.bUUID[6], index.bUUID[7],
index.bUUID[8], index.bUUID[9], index.bUUID[10], index.bUUID[11],
index.bUUID[12], index.bUUID[13], index.bUUID[14], index.bUUID[15]);
if (!strncmp(szTargetUUID, UUID_NULL, sizeof(szTargetUUID)) || !strncmp(szTargetUUID, szUUID, sizeof(szTargetUUID)))
{
if (index.dwOffset && index.dwSize)
{
LPBYTE lpBuffer = new BYTE[index.dwSize];
fseek(fpData, index.dwOffset, SEEK_SET);
if (fread(lpBuffer, 1, index.dwSize, fpData))
{
char szFileName[MAX_PATH];
if (index.wType == 0x0000)
_snprintf(szFileName, sizeof(szFileName), "%s.j2c", szUUID);
else if (index.wType == 0x0001)
_snprintf(szFileName, sizeof(szFileName), "%s.ogg", szUUID);
else if (index.wType == 0x0002)
_snprintf(szFileName, sizeof(szFileName), "%s.callcard", szUUID);
else if (index.wType == 0x0003)
_snprintf(szFileName, sizeof(szFileName), "%s.landmark", szUUID);
else if (index.wType == 0x0004)
_snprintf(szFileName, sizeof(szFileName), "%s.lsl", szUUID);
else if (index.wType == 0x0005)
_snprintf(szFileName, sizeof(szFileName), "%s.clothing", szUUID);
else if (index.wType == 0x0006)
_snprintf(szFileName, sizeof(szFileName), "%s.object", szUUID);
else if (index.wType == 0x0007)
_snprintf(szFileName, sizeof(szFileName), "%s.notecard", szUUID);
else if (index.wType == 0x0008)
_snprintf(szFileName, sizeof(szFileName), "%s.category", szUUID);
else if (index.wType == 0x0009)
_snprintf(szFileName, sizeof(szFileName), "%s.category", szUUID);
else if (index.wType == 0x000a)
_snprintf(szFileName, sizeof(szFileName), "%s.lsl", szUUID);
else if (index.wType == 0x000b)
_snprintf(szFileName, sizeof(szFileName), "%s.lso", szUUID);
else if (index.wType == 0x000c)
_snprintf(szFileName, sizeof(szFileName), "%s.tga", szUUID);
else if (index.wType == 0x000d)
_snprintf(szFileName, sizeof(szFileName), "%s.bodypart", szUUID);
else if (index.wType == 0x000e)
_snprintf(szFileName, sizeof(szFileName), "%s.trash", szUUID);
else if (index.wType == 0x000f)
_snprintf(szFileName, sizeof(szFileName), "%s.snapshot", szUUID);
else if (index.wType == 0x0010)
_snprintf(szFileName, sizeof(szFileName), "%s.lstndfnd", szUUID);
else if (index.wType == 0x0011)
_snprintf(szFileName, sizeof(szFileName), "%s.wav", szUUID);
else if (index.wType == 0x0012)
_snprintf(szFileName, sizeof(szFileName), "%s.tga", szUUID);
else if (index.wType == 0x0013)
_snprintf(szFileName, sizeof(szFileName), "%s.jpg", szUUID);
else if (index.wType == 0x0014)
_snprintf(szFileName, sizeof(szFileName), "%s.animatn", szUUID);
else if (index.wType == 0x0015)
_snprintf(szFileName, sizeof(szFileName), "%s.gesture", szUUID);
else if (index.wType == 0x0016)
_snprintf(szFileName, sizeof(szFileName), "%s.simstate", szUUID);
else
_snprintf(szFileName, sizeof(szFileName), "%s.tmp", szUUID);
printf("Exporting %s\n", szFileName);
DWORD dwWrite = index.dwSize;
if (index.wType == 0x0000)
{
BYTE bOwnerUUID[16];
char szOwnerUUID[37];
WORD wBlockCount = 0;
WORD wBlocksRead = 0;
DWORD dwFileSize = 0;
lpBuffer += 5;
dwWrite -= 5;
memcpy(&bOwnerUUID, lpBuffer, sizeof(bOwnerUUID));
lpBuffer += sizeof(bOwnerUUID);
dwWrite -= sizeof(bOwnerUUID);
_snprintf(szOwnerUUID, sizeof(szOwnerUUID),
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
bOwnerUUID[0], bOwnerUUID[1], bOwnerUUID[2], bOwnerUUID[3],
bOwnerUUID[4], bOwnerUUID[5], bOwnerUUID[6], bOwnerUUID[7],
bOwnerUUID[8], bOwnerUUID[9], bOwnerUUID[10], bOwnerUUID[11],
bOwnerUUID[12], bOwnerUUID[13], bOwnerUUID[14], bOwnerUUID[15]);
memcpy(&wBlockCount, lpBuffer, sizeof(wBlockCount));
lpBuffer += sizeof(wBlockCount);
dwWrite -= sizeof(wBlockCount);
memcpy(&dwFileSize, lpBuffer, sizeof(dwFileSize));
lpBuffer += sizeof(dwFileSize);
dwWrite -= sizeof(dwFileSize);
if (wBlockCount)
{
J2C_BLOCK *lpj2cbData = (J2C_BLOCK *)malloc(sizeof(J2C_BLOCK) * wBlockCount);
ZeroMemory(lpj2cbData, sizeof(J2C_BLOCK) * wBlockCount);
if (lpj2cbData)
{
while (dwWrite > 0)
{
WORD wBlock = 0;
WORD wBlockSize = 0;
memcpy(&wBlock, lpBuffer, sizeof(wBlock));
lpBuffer += sizeof(wBlock);
dwWrite -= sizeof(wBlock);
memcpy(&wBlockSize, lpBuffer, sizeof(wBlockSize));
lpBuffer += sizeof(wBlockSize);
dwWrite -= sizeof(wBlockSize);
//printf("Block: %hu, %hu\n", wBlock, wBlockSize);
lpj2cbData[wBlock].wSize = wBlockSize;
lpj2cbData[wBlock].lpData = (LPBYTE)malloc(wBlockSize);
if (lpj2cbData[wBlock].lpData)
{
memcpy(lpj2cbData[wBlock].lpData, lpBuffer, wBlockSize);
}
lpBuffer += wBlockSize;
dwWrite -= wBlockSize;
wBlocksRead++;
}
if (wBlocksRead == wBlockCount)
{
fpWrite = fopen(szFileName, "wb");
if (fpWrite)
{
for (WORD i = 0; i < wBlockCount; i++)
{
if (lpj2cbData[i].lpData)
{
fwrite(lpj2cbData[i].lpData, 1, lpj2cbData[i].wSize, fpWrite);
}
}
fclose(fpWrite);
char szCmd[MAX_PATH];
sprintf(szCmd, "c:\\progra~1\\irfanview\\i_view32.exe %s /convert=%s.jpg /silent", szFileName, szUUID);
system(szCmd);
//unlink(szFileName);
}
}
for (WORD i = 0; i < wBlockCount; i++)
{
if (lpj2cbData[i].lpData)
{
free(lpj2cbData[i].lpData);
lpj2cbData[i].lpData = NULL;
}
}
free(lpj2cbData);
}
}
}
else
{
fpWrite = fopen(szFileName, "wb");
if (fpWrite)
{
fwrite(lpBuffer, 1, dwWrite, fpWrite);
fclose(fpWrite);
char szCmd[MAX_PATH];
sprintf(szCmd, "c:\\progra~1\\irfanview\\i_view32.exe %s /convert=%s.jpg /silent", szFileName, szUUID);
system(szCmd);
//unlink(szFileName);
}
}
fpWrite = NULL;
}
}
}
nImage++;
}
fclose(fpIndex);
fclose(fpData);
}
return 0;
}
Here are the errors in Borland:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
slice.cpp:
Error E2209 slice.cpp 4: Unable to open include file 'stdafx.h'
Error E2268 slice.cpp 50: Call to undefined function 'printf' in function main(int,char * *)
Error E2268 slice.cpp 54: Call to undefined function 'sprintf' in function main(int,char * *)
Error E2451 slice.cpp 104: Undefined symbol 'FILE' in function slice(char *,char *)
Error E2451 slice.cpp 104: Undefined symbol 'fpIndex' in function slice(char *,char *)
Error E2451 slice.cpp 105: Undefined symbol 'fpData' in function slice(char *,char *)
Error E2451 slice.cpp 106: Undefined symbol 'fpWrite' in function slice(char *,char *)
Error E2268 slice.cpp 108: Call to undefined function 'fopen' in function slice(char *,char *)
Error E2268 slice.cpp 113: Call to undefined function 'fread' in function slice(char *,char *)
Warning W8060 slice.cpp 113: Possibly incorrect assignment in function slice(char *,char *)
Error E2268 slice.cpp 117: Call to undefined function '_snprintf' in function slice(char *,char *)
Error E2268 slice.cpp 129: Call to undefined function 'fseek' in function slice(char *,char *)
Error E2268 slice.cpp 184: Call to undefined function 'printf' in function slice(char *,char *)
Error E2268 slice.cpp 263: Call to undefined function 'fwrite' in function slice(char *,char *)
Error E2268 slice.cpp 267: Call to undefined function 'fclose' in function slice(char *,char *)
Error E2268 slice.cpp 271: Call to undefined function 'sprintf' in function slice(char *,char *)
Error E2268 slice.cpp 297: Call to undefined function 'fwrite' in function slice(char *,char *)
Error E2268 slice.cpp 298: Call to undefined function 'fclose' in function slice(char *,char *)
Error E2268 slice.cpp 302: Call to undefined function 'sprintf' in function slice(char *,char *)
Error E2268 slice.cpp 317: Call to undefined function 'fclose' in function slice(char *,char *)
Error E2268 slice.cpp 318: Call to undefined function 'fclose' in function slice(char *,char *)
Warning W8004 slice.cpp 322: 'nRead' is assigned a value that is never used in function slice(char *,char *)
Warning W8004 slice.cpp 322: 'nMode' is assigned a value that is never used in function slice(char *,char *)
Warning W8057 slice.cpp 322: Parameter 'lpszPathIndex' is never used in function slice(char *,char *)
Warning W8057 slice.cpp 322: Parameter 'lpszPathData' is never used in function slice(char *,char *)
Warning W8059 slice.cpp 324: Structure packing size has changed
*** 20 errors in Compile ***
And here are the MS errors:
Build started: Project: slice, Configuration: Debug|Win32
Command Lines
slice : warning PRJ0041 : Cannot find missing dependency 'winwlm.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macwin32.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'rpcerr.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.slice : warning PRJ0041 : Cannot find missing dependency 'rpcmac.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macname1.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macpub.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macapi.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
slice : warning PRJ0041 : Cannot find missing dependency 'macname2.h' for file 'slice.rc'. Your project may still build, but may continue to appear out of date until this file is found.
Creating temporary file "c:\Documents and Settings\Zaccount\My Documents\Visual Studio 2005\Projects\slice\slice\Debug\RSP00000116683020.rsp" with contents[/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp"Debug\slice.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\slice.cpp"]
Creating command line "cl.exe @"c:\Documents and Settings\Zaccount\My Documents\Visual Studio 2005\Projects\slice\slice\Debug\RSP00000116683020.rsp" /nologo /errorReport:prompt"
Output Window
Compiling...slice.cpp
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(50) : error C3861: 'printf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(54) : error C3861: 'sprintf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(55) : error C3861: 'sprintf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(57) : error C3861: 'printf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(61) : error C2664: 'GetEnvironmentVariableW' : cannot convert parameter 1 from 'const char [8]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(63) : error C3861: 'printf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(67) : error C3861: 'sprintf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(69) : error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(77) : error C2665: 'strrchr' : none of the 2 overloads could convert all the argument types
c:\program files\microsoft visual studio 8\vc\include\string.h
(160): could be 'const char *strrchr(const char *,int)'
c:\program files\microsoft visual studio 8\vc\include\string.h
(185): or 'char *strrchr(char *,int)' while trying to match the argument list '(WCHAR [260], char)'
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(81) : error C3861: 'sprintf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(82) : error C3861: 'sprintf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(84) : error C3861: 'printf': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(108) : error C3861: 'fopen': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(109) : error C3861: 'fopen': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(113) : error C3861: 'fread': identifier not found
c:\documents and settings\zaccount\my documents\visual studio 2005\projects\slice\slice\slice.cpp
(113) : fatal error C1903: unable to recover from previous error(s); stopping compilation