예제 #1
0
//////////////////////////////////////////////////////////
//
// HandleResetSettings
//
//
//
//////////////////////////////////////////////////////////
void HandleResetSettings ( void )
{
    if ( CheckAndShowFileOpenFailureMessage () )
        return;

    CheckAndShowMissingFileMessage();

    SString strSaveFilePath = PathJoin ( GetSystemPersonalPath(), "GTA San Andreas User Files" );
    SString strSettingsFilename = PathJoin ( strSaveFilePath, "gta_sa.set" );
    SString strSettingsFilenameBak = PathJoin ( strSaveFilePath, "gta_sa_old.set" );

    if ( FileExists ( strSettingsFilename ) )
    {
        int iResponse = MessageBoxUTF8 ( NULL, _("There seems to be a problem launching MTA:SA.\nResetting GTA settings can sometimes fix this problem.\n\nDo you want to reset GTA settings now?"), "MTA: San Andreas"+_E("CL08"), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST );
        if ( iResponse == IDYES )
        {
            FileDelete ( strSettingsFilenameBak );
            FileRename ( strSettingsFilename, strSettingsFilenameBak );
            FileDelete ( strSettingsFilename );
            if ( !FileExists ( strSettingsFilename ) )
            {
                AddReportLog ( 4053, "Deleted gta_sa.set" );
                MessageBoxUTF8 ( NULL, _("GTA settings have been reset.\n\nPress OK to continue."), "MTA: San Andreas", MB_OK | MB_ICONINFORMATION | MB_TOPMOST );
            }
            else
            {
                AddReportLog ( 5054, SString ( "Delete gta_sa.set failed with '%s'", *strSettingsFilename ) );
                MessageBoxUTF8 ( NULL, SString ( _("File could not be deleted: '%s'"), *strSettingsFilename ), "Error"+_E("CL09"), MB_OK | MB_ICONWARNING | MB_TOPMOST );
            }
        }
    }
    else
    {
        // No settings to delete, or can't find them
        int iResponse = MessageBoxUTF8 ( NULL, _("Are you having problems running MTA:SA?.\n\nDo you want to see some online help?"), "MTA: San Andreas", MB_YESNO | MB_ICONQUESTION | MB_TOPMOST );
        if ( iResponse == IDYES )
        {
            BrowseToSolution ( "crashing-before-gtalaunch", TERMINATE_PROCESS );
        }
    }
}
예제 #2
0
bool CScriptDebugging::SetLogfile ( const char* szFilename, unsigned int uiLevel )
{
    assert ( szFilename );

    // Close the previously loaded file
    if ( m_pLogFile )
    {
        fprintf ( m_pLogFile, "INFO: Logging to this file ended\n" );
        fclose ( m_pLogFile );
        m_pLogFile = NULL;
    }

    // Apply log size limit
    uint uiMaxSizeKB = 0;
    g_pCore->GetCVars ()->Get ( "max_clientscript_log_kb", uiMaxSizeKB );
    if ( uiMaxSizeKB > 0 )
    {
        uint uiCurrentSizeKB = FileSize ( szFilename ) / 1024;
        if ( uiCurrentSizeKB > uiMaxSizeKB )
        {
            SString strFilenameBackup ( "%s.bak", szFilename );
            FileDelete ( strFilenameBackup );
            FileRename ( szFilename, strFilenameBackup );
            FileDelete ( szFilename );
        }
    }

    // Try to load the new file
    FILE* pFile = fopen ( szFilename, "a+" );
    if ( pFile )
    {
        // Set the new pointer and level and return true
        m_uiLogFileLevel = uiLevel;
        m_pLogFile = pFile;
        return true;
    }

    return false;
}
예제 #3
0
void WorkspaceWork::RenameFile()
{
	if(!filelist.IsCursor()) return;
	String n = GetActiveFileName();
	int i = filelist.GetCursor();
	if(i < 0 || i >= fileindex.GetCount())
		return;
	int ii = fileindex[i];
	WithEditStringLayout<TopWindow> dlg;
	CtrlLayoutOKCancel(dlg, "Rename file");
	dlg.lbl = "New name";
	dlg.text <<= n;
	dlg.Open();
	dlg.text.SetFocus();
	int l = int(GetFileNamePos(n) - ~n);
	int h = int(GetFileExtPos(n) - ~n);
	if(l >= h)
		l = 0;
	dlg.text.SetSelection(l, h);
	if(dlg.Run() != IDOK)
		return;
	n = ~dlg.text;
	String spath = GetActiveFilePath();
	String dpath = SourcePath(GetActivePackage(), n);
	if(!filelist[i].isdir && GetFileLength(spath) >= 0) {
		if(!::MoveFile(spath, dpath)) {
			Exclamation("Failed to rename the file.&&" + GetErrorMessage(GetLastError()));
			return;
		}
	}
	FileRename(dpath);
	int s = filelist.GetSbPos();
	(String &)actual.file[ii] = n;
	SaveLoadPackage(false);
	filelist.SetSbPos(s);
	filelist.SetCursor(i);
	if(GetFileExt(spath) == ".iml" || GetFileExt(dpath) == ".iml")
		SyncWorkspace();
}
예제 #4
0
//
// Cycle (log) files when they reach a certain size.
//
// uiCycleThreshKB - 0 = never cycle   1 = always cycle   >1 cycle when main file reaches this size
//
void SharedUtil::CycleFile( const SString& strPathFilename, uint uiCycleThreshKB, uint uiNumBackups )
{
    if ( uiCycleThreshKB == 0 )
        return;

    if ( uiCycleThreshKB == 1 || FileSize( strPathFilename ) / 1024 > uiCycleThreshKB )
    {
        for( uint i = 0 ; i < uiNumBackups ; i++ )
        {
            // Rename older files .1 .2 etc
            uint uiNew = uiNumBackups - 1 - i;
            uint uiOld = uiNumBackups - i;
            SString strFilenameNewer = strPathFilename + ( uiNew ? SString( ".%d", uiNew ) : "" );
            SString strFilenameOlder = strPathFilename + ( uiOld ? SString( ".%d", uiOld ) : "" );
    
            FileDelete( strFilenameOlder );
            FileRename( strFilenameNewer, strFilenameOlder );
            FileDelete( strFilenameNewer );
        }

        FileDelete( strPathFilename );            
    }
}
예제 #5
0
QByteArray QFileIOService::ExecuteRDSCommand(QRDSServer &rdsserver, quint8 command, const QMap<QString, QString> &map)
{
    QByteArray ret;

    switch (command)
    {
    case QBrowseDirCommand:
        return BrowseDir(rdsserver, map);
        break;
    case QFileReadCommand:
        return FileRead(rdsserver, map);
        break;
    case QFileWriteCommand:
        return FileWrite(rdsserver, map);
        break;
    case QFileRenameCommand:
        return FileRename(rdsserver, map);
        break;
    case QFileRemoveFileCommand:
        return FileRemove(rdsserver, map, true);
        break;
    case QFileRemoveDirectoryCommand:
        return FileRemove(rdsserver, map, false);
        break;
    case QFileExistCommand:
        return Existence(rdsserver, map);
        break;
    case QFileCreateDirCommand:
        return CreateDir(rdsserver, map);
        break;
    case QFileGetRootDirCommand:
        return GetRootDir(rdsserver);
        break;
    }

    return ret;
}
예제 #6
0
int CLuaFileDefs::fileRename ( lua_State* luaVM )
{
//  bool fileRename ( string filePath, string newFilePath )
    SString filePath; SString newFilePath;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( filePath );
    argStream.ReadString ( newFilePath );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );

        if ( !g_pNet->ValidateBinaryFileName ( newFilePath ) )
        {
            argStream.SetCustomError ( SString ( "Filename not allowed %s", *newFilePath ), "File error" );
        }
        else
        if ( pLuaMain )
        {
            std::string strCurAbsPath;
            std::string strNewAbsPath;

            // We have a resource arguments?
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pCurResource = pThisResource;
            CResource* pNewResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( filePath, pCurResource, strCurAbsPath ) &&
                 CResourceManager::ParseResourcePathInput ( newFilePath, pNewResource, strNewAbsPath ) )
            {
                 // Does source file exist?
                if ( FileExists ( strCurAbsPath.c_str() ) )
                {
                    // Does destination file exist?
                    if ( FileExists ( strNewAbsPath.c_str() ) )
                    {
                        argStream.SetCustomError ( SString ( "Destination file already exists (%s)", *newFilePath ), "File error" );
                    }
                    else
                    {
                        // Inform file verifier
                        g_pClientGame->GetResourceManager()->FileModifedByScript( strCurAbsPath );

                        // Make sure the destination folder exist so we can move the file
                        MakeSureDirExists ( strNewAbsPath.c_str () );

                        if ( FileRename ( strCurAbsPath.c_str (), strNewAbsPath.c_str () ) )
                        {
                            // If file renamed/moved return success
                            lua_pushboolean ( luaVM, true );
                            return 1;
                        }
                        else
                        {
                            argStream.SetCustomError ( SString ( "Unable to rename/move %s to %s", *filePath, *newFilePath ), "File error" );
                        }
                    }
                }
                else
                {
                    argStream.SetCustomError ( SString ( "Source file doesn't exist (%s)", *filePath ), "File error" );
                }
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #7
0
int CLuaFileDefs::fileRename ( lua_State* luaVM )
{
//  bool fileRename ( string filePath, string newFilePath )
    SString strCurFile; SString strNewFile;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strCurFile );
    argStream.ReadString ( strNewFile );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            std::string strCurPath;
            std::string strNewPath;
            std::string strCurSubPath;
            std::string strNewSubPath;

            // We have a resource arguments?
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pCurResource = pThisResource;
            CResource* pNewResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( strCurFile, pCurResource, &strCurPath, &strCurSubPath ) &&
                 CResourceManager::ParseResourcePathInput ( strNewFile, pNewResource, &strNewPath, &strNewSubPath ) )
            {
                // Do we have permissions?
                if ( ( pCurResource == pThisResource && 
                       pNewResource == pThisResource ) ||
                     m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                                                        CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                                                        "ModifyOtherObjects",
                                                        CAccessControlListRight::RIGHT_TYPE_GENERAL,
                                                        false ) )
                {
                    string strCurFilePath;
                    string strNewFilePath;

                    // Does `current` file path exist and `new` file path doesn't exist?
                    if ( pCurResource->GetFilePath ( strCurSubPath.c_str(), strCurFilePath ) &&
                        !pNewResource->GetFilePath ( strNewSubPath.c_str(), strNewFilePath ) )
                    {
                        // Make sure the destination folder exist so we can move the file
                        MakeSureDirExists ( strNewPath.c_str () );

                        if ( FileRename ( strCurPath.c_str (), strNewPath.c_str () ) )
                        {
                            // If file renamed/moved return success
                            lua_pushboolean ( luaVM, true );
                            return 1;
                        }
                        else
                        {
                            // Output error
                            m_pScriptDebugging->LogWarning ( luaVM, "%s; unable to rename/move file", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ) );
                        }
                    }
                    else
                    {
                        // Output error
                        m_pScriptDebugging->LogWarning ( luaVM, "%s failed; source file doesn't exist or destination file already exists", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ) );
                    }
                }
                // Do we have not permissions to both - `current` and `new` resources?
                else if ( pThisResource != pCurResource && pThisResource != pNewResource )
                    m_pScriptDebugging->LogError ( luaVM, "%s failed; ModifyOtherObjects in ACL denied resource %s to access %s and %s", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), pThisResource->GetName ().c_str (), pCurResource->GetName ().c_str (), pNewResource->GetName ().c_str () );
                // Do we have not permissions to `current` resource?
                else if ( pThisResource != pCurResource && pThisResource == pNewResource )
                    m_pScriptDebugging->LogError ( luaVM, "%s failed; ModifyOtherObjects in ACL denied resource %s to access %s", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), pThisResource->GetName ().c_str (), pCurResource->GetName ().c_str () );
                // Do we have not permissions to `new` resource?
                else
                    m_pScriptDebugging->LogError ( luaVM, "%s failed; ModifyOtherObjects in ACL denied resource %s to access %s", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), pThisResource->GetName ().c_str (), pNewResource->GetName ().c_str () );
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #8
0
파일: imageio.c 프로젝트: vgurev/freesurfer
/*----------------------------------------------------------------------
            Parameters:

           Description:
              append an image to the end of a hips sequence file, incrementing
              the number of frames recorded in the header.
----------------------------------------------------------------------*/
int
ImageAppend(IMAGE *I, const char*fname)
{
  FILE   *fp ;
  int    ecode, frame = 0, nframes ;
  IMAGE  Iheader, *Iframe ;
  char   tmpname[200] ;

  fp = fopen(fname, "r+b") ;
#if 0
  if (!fp)
    ErrorReturn(-1, (ERROR_NO_FILE, "ImageAppend(%s) failed\n", fname)) ;
#endif

  if (!fp)
    return(ImageWrite(I, fname)) ;

  ecode = fread_header(fp, &Iheader, fname) ;
  if (ecode != HIPS_OK)
    ErrorExit(ERROR_NO_FILE, "ImageAppend: fread_header failed (%d)\n",ecode);

  /* increment # of frames, and update file header */
  Iheader.num_frame++ ;
  nframes = Iheader.num_frame ;
  if (nframes == 10 || nframes == 100 || nframes == 1000)
  {
    /* header size will grow by 1 byte, must copy whole file (ughhh) */
    fclose(fp) ;
    strcpy(tmpname,FileTmpName(NULL)) ;
    FileRename(fname, tmpname) ;

    /* write out new header */
    fp = fopen(fname, "wb") ;
    if (!fp)
      ErrorReturn(-1, (ERROR_NO_FILE, "ImageAppend(%s) failed\n", fname)) ;

    ecode = fwrite_header(fp, &Iheader, fname) ;
    if (ecode != HIPS_OK)
      ErrorExit(ERROR_NO_FILE,"ImageAppend: fwrite_header failed (%d)\n",ecode);

    nframes = Iheader.num_frame - 1 ;
    for (frame = 0 ; frame < nframes ; frame++)
    {
      Iframe = ImageReadFrames(tmpname, frame, 1) ;
      if (!Iframe)
        ErrorReturn(-3, (ERROR_BADFILE,
                         "ImageAppend: could not read %dth frame", frame)) ;
      ecode = fwrite_image(fp, Iframe, frame, fname) ;
      if (ecode != HIPS_OK)
        ErrorReturn(-4, (ERROR_BADFILE,
                         "ImageAppend: fwrite_image frame %d failed (%d)\n",
                         ecode,frame));
    }
    unlink(tmpname) ;
  }
  else    /* seek back to start and increment # of frames */
  {
    if (fseek(fp, 0L, SEEK_SET) < 0)
      ErrorReturn(-2,(ERROR_BADFILE,"ImageAppend(%s): could not seek to end"));
    ecode = fwrite_header(fp, &Iheader, fname) ;
    if (ecode != HIPS_OK)
      ErrorExit(ERROR_NO_FILE,"ImageAppend: fwrite_header failed (%d)\n",ecode);
  }

  if (fseek(fp, 0L, SEEK_END) < 0)
    ErrorReturn(-2, (ERROR_BADFILE, "ImageAppend(%s): could not seek to end"));

  ecode = fwrite_image(fp, I, frame, "fwrite") ;
  if (ecode != HIPS_OK)
    ErrorReturn(-1, (ERROR_BADFILE,
                     "ImageAppend: fwrite_image frame %d failed (%d)\n",ecode,frame));

  free_hdrcon(&Iheader) ;
  fclose(fp) ;
  return(NO_ERROR) ;
}
static int
CreateMemberFile(FILELOCK_FILE_HANDLE entryHandle,  // IN:
                 const LockValues *myValues,        // IN:
                 ConstUnicode entryFilePath,        // IN:
                 ConstUnicode memberFilePath)       // IN:
{
   int err;
   uint32 len;
   char buffer[FILELOCK_DATA_SIZE] = { 0 };

   ASSERT(entryFilePath);
   ASSERT(memberFilePath);

   /*
    * Populate the buffer with appropriate data
    *
    * Lock file arguments are space separated. There is a minimum of 4
    * arguments - machineID, executionID, Lamport number and lock type.
    * The maximum number of argument is FL_MAX_ARGS.
    *
    * The fifth argument, if present, is the payload or "[" if there is no
    * payload and additional arguments are present. The additional arguments
    * form  a properly list - one or more "name=value" pairs.
    */

   Str_Sprintf(buffer, sizeof buffer, "%s %s %u %s %s lc=%s",
               myValues->machineID,
               myValues->executionID,
               myValues->lamportNumber,
               myValues->lockType,
               myValues->payload == NULL ? "[" : myValues->payload,
               myValues->locationChecksum);

   /* Attempt to write the data */
   err = FileLockWriteFile(entryHandle, buffer, sizeof buffer, &len);

   if (err != 0) {
      Warning(LGPFX" %s write of '%s' failed: %s\n", __FUNCTION__,
              UTF8(entryFilePath), strerror(err));

      FileLockCloseFile(entryHandle);

      return err;
   }

   err = FileLockCloseFile(entryHandle);

   if (err != 0) {
      Warning(LGPFX" %s close of '%s' failed: %s\n", __FUNCTION__,
              UTF8(entryFilePath), strerror(err));

      return err;
   }

   if (len != sizeof buffer) {
      Warning(LGPFX" %s write length issue on '%s': %u and %"FMTSZ"d\n",
              __FUNCTION__, UTF8(entryFilePath), len, sizeof buffer);

      return EIO;
   }

   err = FileRename(entryFilePath, memberFilePath);

   if (err != 0) {
      Warning(LGPFX" %s FileRename of '%s' to '%s' failed: %s\n",
              __FUNCTION__, UTF8(entryFilePath), UTF8(memberFilePath),
              strerror(err));

      if (vmx86_debug) {
         Log(LGPFX" %s FileLockFileType() of '%s': %s\n",
             __FUNCTION__, UTF8(entryFilePath),
            strerror(FileAttributesRobust(entryFilePath, NULL)));

         Log(LGPFX" %s FileLockFileType() of '%s': %s\n",
             __FUNCTION__, UTF8(memberFilePath),
            strerror(FileAttributesRobust(memberFilePath, NULL)));
      }

      return err;
   }

   return 0;
}
예제 #10
0
int
LPAFwriteImageAnswer(LPAF *lpaf, int current)
{
  char   *fullname, tmpname[100], fname[100] ;
  IMAGE  Iheader, *I ;
  FILE   *infp, *outfp ;
  int    ecode, frame, nframes, *parms, i, current_frame, type ;
  LP_BOX *lpb ;
  struct extpar *xp ;

  fullname = lpaf->filelist[current] ;

  ImageUnpackFileName(fullname, &current_frame, &type, fname) ;
  if (type != HIPS_IMAGE)
    return(0) ;

  infp = fopen(fname, "rb") ;
  if (!infp)
    ErrorReturn(-1,(ERROR_NO_FILE,
                    "LPAFwriteImageAnswer(%d): could not open %s",
                    current, fname)) ;
  ecode = fread_header(infp, &Iheader, fname) ;
  if (ecode)
  {
    fclose(infp) ;
    ErrorReturn(-2, (ERROR_BADFILE,
                     "LPAFwriteImageAnswer(%d): could not read header", current));
  }
  fclose(infp) ;
  if (Iheader.numparam == 0)  /* must make room for header in image file */
  {
    lpafAllocParms(&Iheader) ;

    /* now copy the old image file to a new one which has room for parms */
    nframes = Iheader.num_frame ;
    strcpy(tmpname, FileTmpName(NULL)) ;
    outfp = fopen(tmpname, "wb") ;
    Iheader.num_frame = 0 ;  /* ImageAppend will bump num_frame on each call */
    ecode = fwrite_header(outfp, &Iheader, tmpname) ;
    fclose(outfp) ;   /* flush file */

    fprintf(stderr, "rewriting image file to make room for parms...\n") ;
    for (frame = 0 ; frame < nframes ; frame++)
    {
      I = ImageReadFrames(fname, frame, 1) ;
      if (!I)
        ErrorExit(ERROR_BADFILE, "LPwriteImageAnswer: could not read frame");
      ImageAppend(I, tmpname) ;
      ImageFree(&I) ;
    }
    FileRename(tmpname, fname) ;
    Iheader.num_frame = nframes ;  /* reset correct # of frames */
  }

  /* now put answer into header */
  lpb = &lpaf->coords[current] ;

  for (frame = 0, xp = Iheader.params ; xp ; xp = xp->nextp)
    if (frame++ == current_frame)
      break ;

  parms = xp->val.v_pi ;
  parms[0] = lpb->xc ;
  parms[1] = lpb->yc ;
  for (i = 0 ; i < NPOINTS ; i++)
  {
    parms[2+2*i] = lpb->xp[i] ;
    parms[2+2*i+1] = lpb->yp[i] ;
  }
  ImageUpdateHeader(&Iheader, fname) ;
  free_hdrcon(&Iheader) ;
  return(1) ;
}
예제 #11
0
int CLuaFileDefs::fileRename ( lua_State* luaVM )
{
//  bool fileRename ( string filePath, string newFilePath )
    SString strInputSrcPath; SString strInputDestPath;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strInputSrcPath );
    argStream.ReadString ( strInputDestPath );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( !pLuaMain )
        {
            lua_pushboolean ( luaVM, false );
            return 1;
        }

#ifdef MTA_CLIENT
        if ( !g_pNet->ValidateBinaryFileName ( strInputDestPath ) )
        {
            argStream.SetCustomError ( SString ( "Filename not allowed %s", *strInputDestPath ), "File error" );
            m_pScriptDebugging->LogError ( luaVM, argStream.GetFullErrorMessage () );

            lua_pushboolean ( luaVM, false );
            return 1;
        }
#endif

        // absPath: the real absolute path to the file
        // metaPath: path relative to the target resource (as would be defined in the meta.xml file)
        SString strSrcAbsPath; SString strDestAbsPath;

        CResource* pThisResource = pLuaMain->GetResource ();
        CResource* pSrcResource = pThisResource;
        CResource* pDestResource = pThisResource;

        if ( CResourceManager::ParseResourcePathInput ( strInputSrcPath, pSrcResource, &strSrcAbsPath ) &&
                CResourceManager::ParseResourcePathInput ( strInputDestPath, pDestResource, &strDestAbsPath ) )
        {
            CheckCanModifyOtherResource( argStream, pThisResource, pSrcResource, pDestResource );
            CheckCanAccessOtherResourceFile( argStream, pThisResource, pSrcResource, strSrcAbsPath );
            CheckCanAccessOtherResourceFile( argStream, pThisResource, pDestResource, strDestAbsPath );
            if ( !argStream.HasErrors() )
            {
                // Does `current` file path exist and `new` file path doesn't exist?
                if ( FileExists(strSrcAbsPath) )
                {
                    if ( !FileExists ( strDestAbsPath ) ) {
#ifdef MTA_CLIENT
                        // Inform file verifier
                        g_pClientGame->GetResourceManager ()->OnFileModifedByScript ( strSrcAbsPath, "fileRename" );
#endif
                        // Make sure the destination folder exists so we can move the file
                        MakeSureDirExists ( strDestAbsPath );

                        if ( FileRename ( strSrcAbsPath, strDestAbsPath ) )
                        {
                            // If file renamed/moved return success
                            lua_pushboolean ( luaVM, true );
                            return 1;
                        }

                        // Output error
                        m_pScriptDebugging->LogWarning ( luaVM, "fileRename failed; unable to rename file" );
                    }
                    else
                    {
                        m_pScriptDebugging->LogWarning ( luaVM, "fileRename failed; destination file already exists" );
                    }
                }
                else
                {
                    m_pScriptDebugging->LogWarning ( luaVM, "fileRename failed; source file doesn't exist" );
                }
            }
        }
    }
    
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #12
0
/** \fn     GalleryView::customEvent(QEvent *)
 *  \brief  Translates the keypresses to specific actions within the plugin
 *  \param  event The custom event
 *  \return void
 */
void GalleryView::customEvent(QEvent *event)
{
    if ((MythEvent::Type)(event->type()) == MythEvent::MythEventMessage)
    {
        MythEvent *me = (MythEvent *)event;
        QString message = me->Message();

        if (message.startsWith("IMAGE_THUMB_CREATED"))
        {
            QStringList tokens = message.simplified().split(" ");
            int fileid = 0;
            if (tokens.size() >= 2)
            {
                fileid = tokens[1].toUInt();

                // FIXME: This sucks, must be a better way to do this
                //
                // get through the entire list of image items and find
                // the fileid that matches the created thumbnail filename
                for (int i = 0; i < m_imageList->GetCount(); i++)
                {
                    MythUIButtonListItem *item = m_imageList->GetItemAt(i);
                    if (!item)
                        continue;

                    ImageMetadata *im = GetImageMetadataFromButton(item);
                    if (!im)
                        continue;

                    if (im->m_id == fileid)
                    {
                        UpdateThumbnail(item, true);
                        break;
                    }
                }
            }
        }
    }
    else if (event->type() == DialogCompletionEvent::kEventType)
    {
        DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);

        QString resultid  = dce->GetId();
        int     buttonnum = dce->GetResult();

        // Confirm current file deletion
        if (resultid == "confirmdelete")
        {
            switch (buttonnum)
            {
            case 0 :
                break;
            case 1 :
                FileDelete();
                break;
            }
        }

        // Confirm all selected file deletion
        if (resultid == "confirmdeleteselected")
        {
            switch (buttonnum)
            {
            case 0 :
                break;
            case 1 :
                FileDeleteSelected();
                break;
            }
        }

        // Synchronize the database
        if (resultid == "confirmstartsync")
        {
            switch (buttonnum)
            {
            case 0 :
                break;
            case 1 :
                // Start the sync, the API call will
                // check if a sync is running already
                m_galleryViewHelper->m_fileHelper->StartSyncImages();

                if (!m_syncStatusThread->isRunning())
                    m_syncStatusThread->start();

                break;
            }
        }

        // Stop the database sync
        if (resultid == "confirmstopsync")
        {
            switch (buttonnum)
            {
            case 0 :
                break;
            case 1 :
                if (m_syncStatusThread->isRunning())
                    m_syncStatusThread->quit();

                m_galleryViewHelper->m_fileHelper->StopSyncImages();
                break;
            }
        }

        if (resultid == "filerename")
        {
            QString newName = dce->GetResultText();
            FileRename(newName);
        }
    }
}