Esempio n. 1
0
int
main(int argc, char *argv[]) 
{
    int i;
    char *destdir;
    char path[PATH_MAX];
    FILE *tznames;

    MemoryManagerOpen("bongo-import-tz");

    if (argc < 3) {
        printf("usage:\n\tbongo-import-tz icsfiles... outputdir\n");
        return 1;
    }
    
    destdir = argv[argc - 1];
    
    snprintf(path, PATH_MAX, "%s/%s", destdir, "generated.tznames");
    tznames = fopen(path, "a");

    for (i = 1; i < argc - 1; i++) {
        ImportFile(argv[i], destdir, tznames);
    }

    fclose(tznames);

    return 0;
}
Esempio n. 2
0
//-------------------------------------------------------------------------------------------------
void ImportSettingsFile( const QString& title, const QString& pathName, QWidget* pParent )
{
    QFileInfo fileInfo( pathName );

    tMessageBox::tStandardButton reply = tMessageBox::Warning( pParent,
        title, 
        QApplication::tr("Replace all existing settings with those from '%1' ? \n(unit will restart)").arg( fileInfo.fileName() ),
        tMessageBox::YES | tMessageBox::NO,
        tMessageBox::NO );

    if (reply == tMessageBox::YES)
    {
        tBusyIndicator* pBusyIndicator = tBusyIndicator::NewBusyIndicator( pParent );
        pBusyIndicator->setFocusPolicy( Qt::NoFocus );
        pBusyIndicator->show();
        QApplication::processEvents();

        bool ok = ImportFile( pathName );
        QApplication::processEvents();

        delete pBusyIndicator;

        if (ok == false)
        {
            tMessageBox::Error( pParent, title, QApplication::tr("Import Failed") );
        }
        RestartApplication();
    }
}
Esempio n. 3
0
// Find MSCORLIB
CAssemblyFile *CAsmLink::GetStdLib()
{
    if (m_pStdLib)
        return m_pStdLib;

    // First search imports
    DWORD i, count;
    CFile *file = NULL;
    HRESULT hr;

    for (i = 0, count = m_pImports->CountFiles(); i < count; i++) {
        hr = m_pImports->GetFile(i, &file);
        if (FAILED(hr))
            break;
        if (file && file->IsStdLib())
            return (m_pStdLib = (CAssemblyFile*)file);
    }

    CComPtr<IMetaDataAssemblyImport> pAImport;
    WCHAR szFilename[MAX_PATH + MAX_PATH];
    mdFile tkFile = mdTokenNil;

    if (FAILED(m_pDisp->GetCORSystemDirectory(szFilename, lengthof(szFilename) - 12, &count)))
        return NULL;
    wcscpy(szFilename + count - 1, L"mscorlib.dll");
    if (FAILED(ImportFile( szFilename, NULL, FALSE, &tkFile, &pAImport, NULL)) || !pAImport)
        return NULL;
    ASSERT(TypeFromToken(tkFile) == mdtAssemblyRef);
    if (FAILED(m_pImports->GetFile(RidFromToken(tkFile), &file)))
        return NULL;
    if (file && file->IsStdLib())
        return (m_pStdLib = (CAssemblyFile*)file);

    return NULL;
}
Esempio n. 4
0
int Ctbg::Readtbg(CString filepath, CStringList &filelist)
{
  int fhandle;
  int ret;

  //take tbg,
  fhandle=open(filepath,O_RDONLY);
  if(fhandle<1) return -2;
  ret=read_tbg(fhandle,-1);
  if(ret==9) return 0;        //handled in read_tbg already
  if(ret==-4)
  {
    lseek(fhandle,0,SEEK_SET);
    ret=read_iap(fhandle,0, filelist); //handle it as an IAP (bundled tbg)
  }
  else
  {
    if(ret<0)
    {
      close(fhandle);
      return ret;
    }
    ret=ImportFile();
  }
  close(fhandle);
  return ret;
}
Esempio n. 5
0
int OpenImage (int nFlags, LONG lParam)
{
    FARPROC   lpfnOpenDlg;
    int       hInFile = 0;                   
    int       nError = EC_ERROR;             
    int       nFileType;                
    OFSTRUCT  Of;
    ATOM  Atom;
    WORD  wBytes;
    int         hTempFile;
    int         nErr = FALSE;

    /*  First get szOpenFileName filled in   */

    switch (nFlags)
    {
        case SCAN_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case USER_OPEN:
    //      CleanFiles ();  BUG HERE????
            lpfnOpenDlg = MakeProcInstance ((FARPROC)OpenDlgProc, hInstIP);
            hInFile = DialogBox (hInstIP, "FILEDLG", hWndIP, lpfnOpenDlg);
            FreeProcInstance (lpfnOpenDlg);
            if (hInFile)
            {
                CleanFiles ();          // Put here instead of before call to dialog
                _lclose (hInFile);      // Kludge..

                /*  Always get image name from path.  Optionally also update the szOpenDir  */

                GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);

                if (szOpenFileName [1] == ':')  // Look for A: or B:, if neither, remember open drive/directory
                {
                    if (! (szOpenFileName [0] == 'A' || szOpenFileName[0] == 'B' || szOpenFileName[0] == 'a' || szOpenFileName[0] == 'b'))
                    {
                        SeparateFile ((LPSTR) szOpenDir, (LPSTR) szImageName, (LPSTR)szOpenFileName);
                        _fstrcpy ((LPSTR) szSaveDir, (LPSTR) szOpenDir);
                    }
                }

                bIsCurrTemp = FALSE;


            }
            else
                nErr = USER_ABANDON;
            bImageModified = FALSE;
        break;

        case COMMAND_LINE_OPEN:
            CleanFiles ();
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case TOOLS_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
        break;

        case OIC_OPEN:
        case AUTO_CONVERT_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case CLIPBOARD_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            _fstrcpy ((LPSTR) szImageName, (LPSTR) "Untitled");
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case GENERIC_OPEN:
        case UNDO_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
        break;

    }

    if (nErr != 0)
        return (nErr);

    hInFile = OpenFile ((LPSTR)szOpenFileName, (LPOFSTRUCT)&Of, OF_READWRITE);

    if (hInFile <= 0)
    {
        if (hInFile == 0)
        hInFile = IDCANCEL;
        nError = hInFile;
        return (nError);
    }

    /* Identify and Import File    */

    if (image_active)
    {
        _fstrcpy ((LPSTR) szTempPath,  (LPSTR) szOpenFileName);     // Store it somewhere

        SendMessage (hWndDisplay, WM_CLOSE, 0, 0);    // Close that baby down!

        if (nFlags == USER_OPEN)                      // So we don't re-display dialog
            nFlags = COMMAND_LINE_OPEN;
        else
            if (nFlags == CLIPBOARD_OPEN)
                nFlags = GENERIC_OPEN;                   

        _lclose (hInFile);

        PostMessage (hWndIP, WM_SHOWIMAGE, nFlags, (LONG) (LPSTR) szTempPath); // Re-prime the pump

        return (0);
    }

    _fstrcpy ((LPSTR) szCurrFileName, (LPSTR) szOpenFileName);  // For having UNDO cap.  5/91

    _llseek (hInFile, 0L, 0);

    nFileType = IdentFormat (hInFile, (LPSTR) szOpenFileName);
    if (nFileType < 0)
    {
        /* File type unknown    */

        _lclose (hInFile);
        hImportFile = 0; 
        return (nFileType);
    }

        switch (nFileType)
        {
            case IDFMT_CCPI:
            {
                char Buffer [128];

                GetTempFileName (0, (LPSTR) "OIC", 0, (LPSTR) Buffer);
                #ifndef DECIPHER
                /* If file type is compressed cpi, decompress first, then re-open     */
                hTempFile = DecompressCPI (hInFile ,(LPSTR) Buffer);
                if (hTempFile > 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (hTempFile);
    
            }
                #else
            return (EC_UFILETYPE);
                #endif
            break;
    
            case IDFMT_WMF:
            {
                char Buffer [128];
                WORD Retval;

                wUserImportType = (WORD) nFileType;
                GetTempFileName (0, (LPSTR) "WMF", 0, (LPSTR) Buffer);
                Retval = wmfImportMetaFile (hWndIP, hInFile, (LPSTR) Buffer);
                if (Retval == 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (USER_ABANDON);
    
            }
            break;

            case IDFMT_CPI:
            break;
    
            default:
    
            if (bDoDisplay)           // If we are going to actually display the thing, we may need to do some stuff first..
            if (bAutoConvert)
            {
                /*  Now if opened image is not CPI, save as CPI and re-open as CPI  */
    
                if (wImportType != IDFMT_CPI)
                    if (bAutoConvert)
                    {
                        wUserImportType = (WORD) nFileType;
                        hImportFile = hInFile;
                        SetState (IMPORT_TYPE, nFileType);  
                        nError = ImportFile();
                        if (nError != 0)
                            return (nError);
                        else
                            return (DoSave (SAVE_TO_CPI)); 
                    }
            }
            break;
        }

    hImportFile = hInFile;      
    SetState (IMPORT_TYPE, nFileType);  
    if (! wUserImportType)
        wUserImportType = wImportType;
    nError = ImportFile();

    if (nError >= 0)
        if (! bDoDisplay)
            PostMessage (hWndIP, WM_COMMAND, IDM_SAVE, 0L);

    return (nError);
}
Esempio n. 6
0
File: file.c Progetto: bbs-io/mbse
/*
 * Upload a file.
 */
int Upload()
{
    int		    Area, rc;
    unsigned int    OldArea;
    char	    *arc, *temp;
    up_list	    *up = NULL, *tmpf;

    WhosDoingWhat(UPLOAD, NULL); 
    Enter(1);
    Area = OldArea = iAreaNumber;

    /*
     * If there is a special upload area for the current area
     * then select it.
     */
    if (area.Upload)
	Area = area.Upload;
    SetFileArea(Area);
    Syslog('+', "Upload area is %d %s", Area, area.Name);

    /*
     * Check upload access for the real upload directory.
     */
    if (!Access(exitinfo.Security, area.UPSec)) {
	Enter(1);
	/* You do not have enough access to upload to this area */
	pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(278));
	Enter(2);
	SetFileArea(OldArea);
	Pause();
	return 0;
    }

    clear();
    Enter(2);

    rc = upload(&up);

    if (rc) {
	Syslog('+', "Upload failed, rc=%d", rc);
	SetFileArea(OldArea);
	return 0;
    }
    Syslog('b', "upload done, start checks");

    Enter(2);
    pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"Checking your upload(s)");
    Enter(1);

    temp = calloc(PATH_MAX, sizeof(char));
    for (tmpf = up; tmpf; tmpf = tmpf->next) {
	snprintf(temp, PATH_MAX, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name);
	chdir(temp);

	Syslog('b', "Checking upload %s", tmpf->filename);
	if ((arc = GetFileType(tmpf->filename)) == NULL) {
	    /*
	     * If the filetype is unknown, it is probably 
	     * a textfile or so. Import it direct.
	     */
	    Syslog('b', "Unknown file type");
	    if (!ScanDirect(basename(tmpf->filename)))
		ImportFile(tmpf->filename, Area, FALSE, tmpf->size);
	} else {
	    /*
	     * We figured out the type of the uploaded file.
	     */
	    Syslog('b', "File type is %s", arc);

	    /*
	     * MS-DOS executables are handled direct.
	     */
	    if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) {
	        if (!ScanDirect(basename(tmpf->filename))) 
		   ImportFile(tmpf->filename, Area, FALSE, tmpf->size);
	    } else {
		switch (ScanArchive(basename(tmpf->filename), arc)) {
		    case 0: ImportFile(tmpf->filename, Area, TRUE, tmpf->size);
			    break;
		    case 1: break;
		    case 2: break;
		    case 3: /*
			     * No valid unarchiver found, just import after scanning,
			     * may catch macro viri.
			     */
			    if (!ScanDirect(basename(tmpf->filename)))
				ImportFile(tmpf->filename, Area, FALSE, tmpf->size);
			    break;
		}
	    }
	}
    }

    tidy_upload(&up);
    free(temp);
    Home();
    SetFileArea(OldArea);
    Pause();
    return 1;
}
Esempio n. 7
0
bool TextViewBase::HandleWndProc(UINT msg, WPARAM wParam, LPARAM lParam, LONG *pResult)
{
	HIMC hIMC = NULL;
	switch (msg)
	{
		// Draw contents of TextView whenever window needs updating
	case WM_ERASEBKGND:
		*pResult = 1;
		return true;
		// Need to custom-draw the border for XP/Vista themes
	case WM_NCPAINT:
		*pResult = OnNcPaint((HRGN)wParam);
		return true;

	case WM_PAINT:
		*pResult = OnPaint();
		return true;
		// Set a new font 
	case WM_SETFONT:
		*pResult = OnSetFont((HFONT)wParam);
		return true;

	case WM_SIZE:
		*pResult = OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
		return true;

	case WM_VSCROLL:
		*pResult = OnVScroll(LOWORD(wParam), HIWORD(wParam));
		return true;

	case WM_HSCROLL:
		*pResult = OnHScroll(LOWORD(wParam), HIWORD(wParam));
		return true;

	case WM_MOUSEACTIVATE:
		*pResult = OnMouseActivate((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
		return true;

		//case WM_CONTEXTMENU:
		//	return OnContextMenu((HWND)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));

	case WM_MOUSEWHEEL:
		if (IsKeyPressed(VK_CONTROL))
			return false;
		else
			*pResult = OnMouseWheel((short)HIWORD(wParam));
		return true;

	case WM_SETFOCUS:
		*pResult = OnSetFocus((HWND)wParam);
		return true;

	case WM_KILLFOCUS:
		*pResult = OnKillFocus((HWND)wParam);
		return true;

		// make sure we get arrow-keys, enter, tab, etc when hosted inside a dialog
	case WM_GETDLGCODE:
		*pResult = DLGC_WANTALLKEYS;//DLGC_WANTMESSAGE;//DLGC_WANTARROWS;
		return true;

	case WM_LBUTTONDOWN:
		*pResult = OnLButtonDown(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
		return true;

	case WM_LBUTTONUP:
		*pResult = OnLButtonUp(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
		return true;

	case WM_LBUTTONDBLCLK:
		*pResult = OnLButtonDblClick(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
		return true;

	case WM_RBUTTONDOWN:
		*pResult = OnRButtonDown(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
		return true;
	case WM_MOUSEMOVE:
		*pResult = OnMouseMove(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
		return true;

	case WM_KEYDOWN:
		*pResult = OnKeyDown(wParam, lParam);
		return true;

	case WM_UNDO: case TXM_UNDO: case EM_UNDO:
		*pResult = Undo();
		return true;

	case TXM_REDO : case EM_REDO:
		*pResult = Redo();
		return true;

	case TXM_CANUNDO: case EM_CANUNDO:
		*pResult = CanUndo();
		return true;

	case TXM_CANREDO: case EM_CANREDO:
		*pResult = CanRedo();
		return true;

	case WM_CHAR:
		OutputDebugString(L"WM_CHAR\n");
		*pResult = OnChar(wParam, lParam);
		return true;

	case WM_SETCURSOR:

		if (LOWORD(lParam) == HTCLIENT)
		{
			*pResult = TRUE;
			return true;
		}
		else
			return false;
	case WM_COPY:
		*pResult = OnCopy();
		return true;

	case WM_CUT:
		*pResult = OnCut();
		return true;

	case WM_PASTE:
		*pResult = OnPaste();
		return true;

	case WM_CLEAR:
		*pResult = OnClear();
		return true;
	
	case WM_GETTEXT:
		*pResult = GetText((WCHAR*)lParam, 0, (ULONG)wParam);
		return true;

	case WM_SETTEXT:
		*pResult = OnSetText((WCHAR*)lParam, lstrlen((WCHAR*)lParam));
		return true;
		//case TXM_SETTEXT:
		//	{
		//		ClearFile();
		//		EnterText((WCHAR*)lParam, (LONG)wParam);
		//		return 0;
		//	}
	case WM_TIMER:
		*pResult = OnTimer(wParam);
		return true;

	case WM_IME_STARTCOMPOSITION:
		OutputDebugString(L"WM_IME_STARTCOMPOSITION\n");
		*pResult = OnStartComposition(wParam, lParam);
		return true;
		//return DefWindowProc(m_hWnd, WM_IME_STARTCOMPOSITION, wParam, lParam);

	case WM_IME_COMPOSITION:
		OutputDebugString(L"WM_IME_COMPOSITION\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_COMPOSITION, wParam, lParam);
		return true;
		//return OnComposition(wParam, lParam);

	case WM_IME_ENDCOMPOSITION:
		OutputDebugString(L"WM_IME_ENDCOMPOSITION\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_ENDCOMPOSITION, wParam, lParam);
		return true;
		//return OnEndComposition(wParam, lParam);

	case WM_IME_CHAR:
		OutputDebugString(L"WM_IME_CHAR\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_CHAR, wParam, lParam);
		return true;

	case WM_IME_CONTROL:
		OutputDebugString(L"WM_IME_CONTROL\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_CONTROL, wParam, lParam);
		return true;


	case WM_IME_NOTIFY:
		OutputDebugString(L"WM_IME_NOTIFY\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_NOTIFY, wParam, lParam);
		return true;
		//return HandleImeNotify(wParam, lParam);

	case WM_IME_REQUEST:
		OutputDebugString(L"WM_IME_REQUEST\n");
		*pResult = DefWindowProc(m_hWnd, WM_IME_REQUEST, wParam, lParam);
		return true;
	case WM_INPUTLANGCHANGE:
		*pResult = OnInputLanChange(wParam, lParam);
		return true;

	case TXM_PRINT:
		*pResult = OnPrint((HDC)wParam, (int)lParam);
		return true;

		//
	case TXM_OPENFILE:
		*pResult = OpenFile((TCHAR *)lParam);
		return true;


	case TXM_SAVEFILE:
		*pResult = SaveFile((TCHAR *)lParam);
		return true;

	case TXM_IMPORTFILE:
		*pResult = ImportFile((TCHAR *)lParam, (int)wParam);
		return true;

	case TXM_EXPORTFILE:
	{
		int convertype = LOWORD(wParam);
		int utf_type = HIWORD(wParam);
		*pResult = ExportFile((TCHAR *)lParam, convertype, utf_type);
		return true;
	}

	case TXM_CLEAR:
		*pResult = ClearFile();
		return true;

	case TXM_GETFORMAT:
		*pResult = m_pTextDoc->getformat();
		return true;

	case TXM_SETFORMAT:
		*pResult = m_pTextDoc->setformat((int)wParam);
		return true;

	case TXM_GETSELSIZE:
		*pResult = SelectionSize();
		return true;

	case TXM_SETSELALL:
		*pResult = SelectAll();
		return true;

	case TXM_GETCURPOS:
		*pResult = m_CurrentCharPos.get();
		return true;

	case TXM_GETCURLINE_D:
		*pResult = m_nCurrentLine_D;
		return true;

	case TXM_GETCURLINE_V:
		*pResult = OnGetCurLineV();
		return true;

	case TXM_GETCURCOL:
		*pResult = OnGetCurCol();
		return true;

	case TXM_GETEDITMODE:
		*pResult = m_nEditMode;
		return true;

	case TXM_SETEDITMODE:
		lParam = m_nEditMode;
		m_nEditMode = wParam;
		*pResult = lParam;
		return true;
	case TXM_FIND_INIT:
		FindInitial((WCHAR*)lParam);
		*pResult = 0;
		return true;
	case TXM_FIND:
	{
		BOOL m = (BOOL)LOWORD(wParam);
		BOOL b = (BOOL)HIWORD(wParam);
		//FindText()
		if (b)
			*pResult = FindBackward(m, NULL);
		else
			*pResult = FindForward(m, NULL);
		return true;
	}
	case TXM_FIND_TEXT:
	{
		FIND_OPTION* fp = (FIND_OPTION*)(lParam);
		*pResult = Find_Text(fp->text, lstrlen(fp->text), fp->fBackward, fp->fMachCase, fp->fWarp);
		return true;
	}
	case TXM_REPLACE_TEXT:
	{
		*pResult = Replace_Text((REPLACE_OPTION*)(lParam));
		return true;
	}
	case TXM_SETRESMODULE:
	{
		*pResult = OnSetResModule((HMODULE)lParam);
		return true;
	}
	case WM_GETTEXTLENGTH:
	case TXM_GETTEXTLEN:
	{
		*pResult = OnGetTextLen();
		return true;
	}
	case TXM_REPLACE:
	{
		BOOL ra = (BOOL)LOWORD(wParam);
		WORD mb = (WORD)HIWORD(wParam);
		BOOL m = (BOOL)LOBYTE(mb);
		BOOL b = (BOOL)HIBYTE(mb);
		if (b)
			*pResult = FindBackward(m, (WCHAR*)lParam, ra);
		else
			*pResult = FindForward(m, (WCHAR*)lParam, ra);
		return true;
	}
	case TXM_FIND_GETTEXTLENGTH:
		*pResult = m_pFndIterator->find_text_length();
		return true;
	case TXM_GETSELSTART:
		*pResult = m_nSelectionStart;
		return true;
	case TXM_GETSELEND:
		*pResult = m_nSelectionEnd;
		return true;
	case TXM_GETSELTEXT:
		*pResult = OnGetSelText((WCHAR*)wParam, ULONG(lParam));
		return true;
	case TXM_SETTESTERMODE:
		OnTesterMode((bool)wParam);
		*pResult = 0;
		return true;
	case TXM_SETCONTEXTMENU:
		m_hUserMenu = (HMENU)wParam;
		*pResult = 0;
		return true;
	case TXM_STATISTIC:
		*pResult = OnDoStatistic((STATISTIC*)(lParam));
		return true;
	case TXM_GETCONVERTTYPES:
		*pResult = OnGetConvertTypes((convert_type*)(lParam));
		return true;
	case EM_GETSEL:
		*pResult = OnMsg_EM_GETSEL((ULONG*)wParam, (ULONG*)lParam);
		return true;
	case EM_SETSEL:
		*pResult = OnMsg_EM_SETSEL((LONG)wParam, (LONG)lParam);
		return true;
	default:
		return false;
	}
}
Esempio n. 8
0
int Ctbg::read_iap(int fhandle, int onlyopen, CStringList &filelist)
{
  char *filedata;
  char tmpfilename[MAX_PATH];
  CString outfilepath, syscommand;
  int esize, iapfullsize;
  int fhandle2;
  int ret;
  int hasweidu;
  int maxlen;

  hasweidu=1;
  maxlen=filelength(fhandle);
  if(maxlen<sizeof(iapheader) ) return -1; //short file, invalid item
  if(read(fhandle,&iapheader,sizeof(iapheader) )!=sizeof(iapheader) )
  {
    return -2;
  }
  if(memcmp(iapheader.signature,"IAP",3) ) return -4; // not iap
  if(iapheader.totallen!=maxlen) return -1; //iap total length is invalid
  actfilecount=0;
  iapfullsize=sizeof(iapheader);
  
  KillIapFileHeaders();
  iapfileheaders=new iap_file_header[iapheader.tbgcount+iapheader.othercount];
  if(!iapfileheaders) return -3;
  iapfilecount=iapheader.tbgcount+iapheader.othercount;
  esize=iapfilecount*sizeof(iap_file_header);
  if(read(fhandle,iapfileheaders,esize)!=esize)
  {
    return -2;
  }
  iapfullsize+=esize;
  if(onlyopen)
  {
    AllocateHeaders(iapheader.tbgcount,iapheader.othercount);
  }

  //handle tbg files, iap files
  for(actfilecount=0;actfilecount<iapfilecount;actfilecount++)
  {
    if(iapfileheaders[actfilecount].nameoffset!=iapfullsize) return -2;
    esize=iapfileheaders[actfilecount].namelength;
    iapfullsize+=esize;
    if(iapfullsize>maxlen) return -2;
    if(esize>=MAX_PATH) return -3;
    if(read(fhandle,tmpfilename,esize)!=esize) return -2;
    outfilepath=bgfolder+CString(tmpfilename,esize);
    
    if(iapfileheaders[actfilecount].fileoffset!=iapfullsize) return -2;
    esize=iapfileheaders[actfilecount].filelength;
    iapfullsize+=esize;
    if(iapfullsize>maxlen) return -2;
    if(actfilecount<iapheader.tbgcount)
    { //tbg file
      if(onlyopen)
      {
        m_tbgnames[actfilecount]=outfilepath;
        lseek(fhandle,esize,SEEK_CUR);
        continue;
      }
      ret=read_tbg(fhandle,esize);
      if(ret<0) return ret;
      if(ret==9) return 0;  //handled in read_tbg already
      ret=ImportFile();
      if(ret<0) return ret;
      continue;
    }
    //plain file
    if(onlyopen)
    {
      m_othernames[actfilecount-iapheader.tbgcount]=outfilepath;
      lseek(fhandle,esize,SEEK_CUR);
      continue;
    }
    filedata=new char[esize+1];
    if(!filedata) return -3;
    filedata[esize]=0; //for using it as a string
    if(read(fhandle,filedata,esize)!=esize)
    {
      delete [] filedata;
      return -2;
    }
    fhandle2=creat(outfilepath,S_IWRITE);
    if(fhandle2<1) return -2;
    if(write(fhandle2,filedata,esize)!=esize) ret=-2;
    else ret=0;
    close(fhandle2);
    if(ret<0)
    {
      delete [] filedata;
      return ret;
    }
    if((iapfileheaders[actfilecount].launchflag&2) && hasweidu)
    {
      delete [] filedata;
      if(weidupath.IsEmpty())
      {
        MessageBox(0,"Can't import dialog source without WeiDU installed!","Warning",MB_ICONEXCLAMATION|MB_OK);
        hasweidu=0;
        continue;
      }
      filelist.AddTail(outfilepath);
      continue;
    }
    if((iapfileheaders[actfilecount].launchflag&1) )
    {
      //if(esize>4096) filedata[4096]=0;
      //MessageBox(0,filedata,"IAP import",MB_OK);
      CTextView dlg;
      dlg.m_text=filedata;
      dlg.m_file=outfilepath;
      dlg.DoModal();
      delete [] filedata;
      continue;
    }
    delete [] filedata;
  }

  if(iapfullsize!=maxlen) return -1;
  return 0;
}