Beispiel #1
0
bool System_RemoveDir(char * path)
{
   bool result = false;
   char location[MAX_LOCATION] = "";
   int locationLen = 0;
   int c = 0;
#ifdef __WIN32__
   if(path[0] && path[1] == ':')
      c = 2;
   else if(path[0] == '\\' && path[1] == '\\')
      c = 2;
   else
#endif
   if(path[0] == '/' || path[0] == '\\')
      c = 1;

   strncpy(location, path, c);
   location[c] = '\0';
   locationLen = c;

   for(; path[c]; )
   {
      char directory[MAX_FILENAME];
      int len = 0;
      char ch;
      for(;(ch = path[c]) && (ch == '/' || ch == '\\'); c++);
      for(;(ch = path[c]) && (ch != '/' && ch != '\\'); c++)
      {
         if(len < MAX_FILENAME)
            directory[len++] = ch;  
      }
      directory[len] = '\0';
      if(locationLen > 0 &&
         (location[locationLen-1] != '\\' && location[locationLen-1] != '/'))
         strcat(location, DIR_SEPS);
      strcat(location, directory);
      locationLen = strlen(location);

      if(FILE_FileExists(location) == isDirectory)
      {
#if defined(__unix__) || defined(__APPLE__)
         rmdir(location);
#else
         uint16 _wlocation[MAX_LOCATION];
         __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(location, _wlocation, MAX_LOCATION);
         _wrmdir(_wlocation);
#endif
         result = true;
      }
   }
   return result;
}
Beispiel #2
0
bool System_ShellOpen(char * fileName, va_list args)
{
   bool result = false;
   char filePath[MAX_F_STRING];
   int len;
   
#if defined(__WIN32__)
   filePath[0] = '"';
   vsprintf(filePath+1, fileName, args);
#else
   vsprintf(filePath, fileName, args);
#endif
   len = strlen(filePath);
#if defined(__WIN32__)
   filePath[len] = '"';
   filePath[len+1] = '\0';
#else
   filePath[len] = '\0';
#endif

#if !defined(__WIN32__)
   {
      char command[MAX_LOCATION] = "";
      char desktop[MAX_F_STRING];
      __ecereNameSpace__ecere__sys__GetEnvironment("ECERE_DESKTOP", desktop, sizeof(desktop));
      if(__ecereNameSpace__ecere__sys__SearchString(desktop, 0, "ecere", false, false))
         sprintf(command, "ede-open \"%s\" &", filePath);
      else
      {
         __ecereNameSpace__ecere__sys__GetEnvironment("DESKTOP_SESSION", desktop, sizeof(desktop));
         if(__ecereNameSpace__ecere__sys__SearchString(desktop, 0, "gnome", false, false))
            sprintf(command, "gnome-open \"%s\" &", filePath);
         else if(__ecereNameSpace__ecere__sys__SearchString(desktop, 0, "kde", false, false))
            sprintf(command, "kde-open \"%s\" &", filePath);
         else
         {
            if(FILE_FileExists(filePath) != isDirectory)
               sprintf(command, "%s &", filePath);
         }
      }

      if(command[0] && system(command) != -1)
         result = true;
   }
#elif defined(ECERE_VANILLA)
   {
      uint16 * _wfilePath = __ecereNameSpace__ecere__sys__UTF8toUTF16(filePath, null);
      if(_wsystem(_wfilePath) != -1)
         result = true;
      __ecereNameSpace__ecere__com__eSystem_Delete(_wfilePath);
   }
#else
   {
      uint16 * _wfilePath = __ecereNameSpace__ecere__sys__UTF8toUTF16(filePath, null);
      char curDir[MAX_LOCATION];
      uint16 * _wcurDir;
      __ecereNameSpace__ecere__sys__StripLastDirectory(filePath, curDir);
      _wcurDir = __ecereNameSpace__ecere__sys__UTF8toUTF16(curDir, null);
      //if(ShellExecute(null, "open", _wfilePath, null, curDir, SW_SHOWNORMAL) > 32)
      if((void *)ShellExecute(null, null, _wfilePath, null, _wcurDir, SW_SHOWNORMAL) > (void *)32)
         result = true;
      __ecereNameSpace__ecere__com__eSystem_Delete(_wfilePath);
      __ecereNameSpace__ecere__com__eSystem_Delete(_wcurDir);
   }
#endif
   return result;
}
Beispiel #3
0
/////////////////////////////////////////////////////////////////////////////
// Restore configuration from /SYSEX/<device>/DEVCFG.V4 file
/////////////////////////////////////////////////////////////////////////////
static s32 SEQ_UI_SYSEX_RestoreConfig(void)
{
  s32 status = 0;

  if( !dir_name[0] ) {
    // not in device dir
    return -1;
  }

  file_t file;
  char filepath[MAX_PATH];
  sprintf(filepath, "/SYSEX/%s/DEVCFG.V4", dir_name);

  MUTEX_SDCARD_TAKE;

  if( (status=FILE_ReadOpen(&file, filepath)) < 0 ) {
    // no error if file doesn't exist...
    if( FILE_FileExists(filepath) >= 1 ) {
      DEBUG_MSG("[SEQ_UI_SYSEX] Failed to open %s file, status: %d\n", filepath, status);
      SEQ_UI_SDCardErrMsg(2000, status);
    }
    // take default values
    sysex_port = DEFAULT;
    sysex_delay_between_dumps = 100;
  } else {
    char line_buffer[128];
    do {
      status=FILE_ReadLine((u8 *)line_buffer, 128);

      // sscanf consumes too much memory, therefore we parse directly
      char *separators = " \t";
      char *brkt;
      char *parameter;

      if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {

	if( *parameter == '#' ) {
	  // ignore comments
	} else {
	  char *word = strtok_r(NULL, separators, &brkt);

	  if( strcasecmp(parameter, "DevicePort") == 0 ) {
	    s32 value = SEQ_MIDI_PORT_OutPortFromNameGet(word);
	    if( value < 0 ) {
	      DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: invalid parameter value: %s %s\n", parameter, word);
	    } else {
	      sysex_port = value;
	    }
	  } else if( strcasecmp(parameter, "DelayBetweenDumps") == 0 ) {
	    s32 value = get_dec(word);
	    if( value < 0 || value > 65535 ) {
	      DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: invalid parameter value: %s %s\n", parameter, word);
	    } else {
	      sysex_delay_between_dumps = value;
	    }
	  } else {
	    DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: unknown parameter: %s\n", parameter);
	  }
	}
      }

    } while( status >= 1 );

    // close file
    status |= FILE_ReadClose(&file);

    if( status < 0 ) {
      DEBUG_MSG("[SEQ_UI_SYSEX] Errors while reading from %s file\n", filepath);
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Errors while reading from", filepath);
    }
  }

  MUTEX_SDCARD_GIVE;

  return status;
}