示例#1
0
/*
 * TODO:
 * - not topmost
 * - resize stuff
 * - ask to save in exit (check if changed)
 */
BOOL CALLBACK PatchBDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {

	int tmpi,i;
	char fileName[MAX_PATH], *tmpStr;
	FILE *fp;

	switch(uMsg) {

		case WM_INITDIALOG:
            SetWindowText(hW, _("Patches Browser"));
            Button_SetText(GetDlgItem(hW,IDC_REFRESHPATCHLIST), _("Refresh List"));
            Button_SetText(GetDlgItem(hW,IDC_NEWPATCH), _("New Patch"));
			Button_SetText(GetDlgItem(hW,IDC_SAVEPATCH), _("Save Patch"));
			Button_SetText(GetDlgItem(hW,IDC_EXITPB), _("Exit"));
            Static_SetText(GetDlgItem(hW,IDC_GAMENAMESEARCH), _("Search game name patch:")); 
			//List Patches
			ListPatches ((HWND) hW);
			return TRUE;

		case WM_COMMAND:
			switch(LOWORD(wParam)) {

				case IDC_NEWPATCH:

					i = Save_Patch_Proc(fileName);
					if ( i == FALSE || (fp = fopen(fileName,"a")) == NULL ) { 
						MessageBox(hW,(LPCTSTR)"Couldn't create the file.",NULL,(UINT)MB_ICONERROR);
						return FALSE;
					}

					fclose(fp);
					i = MessageBox(hW,(LPCTSTR)"File created sucessfully.\nClear textbox?",NULL,(UINT)(MB_YESNO|MB_ICONQUESTION));
					if (i==IDYES) SetDlgItemText(hW, IDC_PATCHTEXT, (LPCTSTR)""); 

					return TRUE;

				case IDC_SAVEPATCH:

					i = Save_Patch_Proc(fileName);
					if ( i == FALSE || (fp = fopen(fileName,"w")) == NULL ) { 
						MessageBox(hW,(LPCTSTR)"Couldn't save the file.",NULL,(UINT)MB_ICONERROR);
						return FALSE;
					}

					tmpi = SendDlgItemMessage(hW, IDC_PATCHTEXT, EM_GETLINECOUNT, (WPARAM)NULL, (LPARAM)NULL);
					i=0;
					for (;tmpi>=0;tmpi--)
						i += SendDlgItemMessage(hW, IDC_PATCHTEXT, EM_LINELENGTH, (WPARAM)tmpi, (LPARAM)NULL);

					tmpStr = (char *) malloc(i);
					sprintf(tmpStr,"");
					SendDlgItemMessage(hW, IDC_PATCHTEXT, WM_GETTEXT, (WPARAM)i, (LPARAM)tmpStr);

					//remove \r
					for (i=0,tmpi=0; tmpStr[i]!='\0'; i++)
						if (tmpStr[i] != '\r')
							tmpStr[tmpi++] = tmpStr[i];
					tmpStr[tmpi] = '\0';

					fputs(tmpStr,fp);

					fclose(fp);
					free(tmpStr);

					MessageBox(hW,(LPCTSTR)"File saved sucessfully.",NULL,(UINT)MB_ICONINFORMATION);

					return TRUE;

				case IDC_REFRESHPATCHLIST:

					//List Patches
					ListPatches ((HWND) hW);

					return TRUE;

				case IDC_EXITPB:

					//Close Dialog
					EndDialog(hW, FALSE);

					return TRUE;

				case IDC_PATCHCRCLIST:

					//Get selected item
					tmpi = SendDlgItemMessage(hW, IDC_PATCHCRCLIST, LB_GETCURSEL, 0, 0);
					SendDlgItemMessage(hW, IDC_PATCHCRCLIST, LB_GETTEXT, (WPARAM)tmpi, (LPARAM)fileName);

					return ReadPatch ((HWND) hW, fileName);

				case IDC_PATCHNAMELIST:

					//Get selected item
					tmpi = SendDlgItemMessage(hW, IDC_PATCHNAMELIST, LB_GETCURSEL, 0, 0);
					SendDlgItemMessage(hW, IDC_PATCHNAMELIST, LB_GETTEXT, (WPARAM)tmpi, (LPARAM)fileName);

					//another small hack :p
					//eg. SOCOM Demo PAL (7dd01dd9.pnach)
					for (i=0;i<(int)strlen(fileName);i++)
						if (fileName[i] == '(') tmpi = i;

					sprintf(fileName,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
						fileName[tmpi+1],fileName[tmpi+2],fileName[tmpi+3],
						fileName[tmpi+4],fileName[tmpi+5],fileName[tmpi+6],
						fileName[tmpi+7],fileName[tmpi+8],fileName[tmpi+9],
						fileName[tmpi+10],fileName[tmpi+11],fileName[tmpi+12],
						fileName[tmpi+13],fileName[tmpi+14]);

					//sanity check
					if (fileName[tmpi+15] != ')') return FALSE;

					return ReadPatch ((HWND) hW, fileName);

				case IDC_SEARCHPATCHTEXT:

					//get text
					SendDlgItemMessage(hW, IDC_SEARCHPATCHTEXT, EM_GETLINE, 0, (LPARAM)fileName);
					//search
					tmpi = SendDlgItemMessage(hW, IDC_PATCHNAMELIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)fileName);
					//select match item 
					SendDlgItemMessage(hW, IDC_PATCHNAMELIST, LB_SETCURSEL, (WPARAM)tmpi, (LPARAM)NULL);

					return TRUE;
			}
			return TRUE;

		case WM_CLOSE:
			EndDialog(hW, FALSE);
			break;

	}
	return FALSE;
}
示例#2
0
void clGeometryReader::ReadSurface(fstream &file, clSurface &surface) const
{
  int EndOfBlock    = 0;

  // Read line
  char line[LINE_SIZE];
  file.getline(line, LINE_SIZE);

  while(!file.eof() && file.good() && !EndOfBlock)
  {
    // Check first character in trimmed line
    switch(*strtrim(line))
    {
      case '#':
      case '*':
        // Comment line
        file.getline(line, LINE_SIZE);
        break;
      case '$':
      case '&':
      {
        // Block specifier
        int blockCommand = GetBlockSpec(line);

        switch(blockCommand)
        {
          case UNKNOWN_SPEC:
            throw clExceptionTree("clGeometryReader", "ReadSurface", "Unknown block specifier.");
            break;
          case POINT_SPEC:
          {
            // Start of point block
            dMatrix pointsX, pointsY, pointsZ;

            ReadPoints(file, pointsX, pointsY, pointsZ);
            surface.CreatePatches(pointsX, pointsY, pointsZ);

            file.getline(line, LINE_SIZE);
            break;
          }
          case PATCH_SPEC:
          {
            // Start of patch block
            clPatch *patch = new clPatch;

            ReadPatch(file, *patch);
            surface.AddPatch(patch);

            file.getline(line, LINE_SIZE);
            break;
          }
          case SURFACE_SPEC:
            // Start of surface block
            throw clExceptionTree("clGeometryReader", "ReadSurface", "Unexpected start of block SURFACE.");
            break;
          case GEOMETRY_SPEC:
            // Start of geometry block
            throw clExceptionTree("clGeometryReader", "ReadSurface", "Unexpected start of block GEOMETRY.");
            break;
          case END_SPEC:
            // End of geometry block specification
            EndOfBlock = 1;
            break;
          default:
            throw clExceptionTree("clGeometryReader", "ReadSurface", "Function GetBlockSpec returned unknown value.");
            break;
        }

        break;
      }
      case '/':
        // End of geometry block specification
        EndOfBlock = 1;
        break;
      default:
        file.getline(line, LINE_SIZE);
        break;
    }
  }
}