Example #1
0
void tap_folder_dodeletedir(t_folder *x, t_symbol *s, long argc, t_atom *argv)
{
	char	name[MAX_PATH_CHARS];

#ifdef MAC_VERSION
	char	script[MAX_PATH_CHARS + 200];
	t_atom	a;
	
	path_nameconform(s->s_name, name, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
	snprintf(script, MAX_PATH_CHARS + 200, 
		"tell application \"Finder\" \ntry \nset thing to \"%s\" as POSIX file \ndelete thing \nend try \nend tell \n",
		name);
	atom_setsym(&a, gensym(script));
	object_method_typed(x->applescript, gensym("script"), 1, &a, NULL);
	object_method(x->applescript, _sym_bang);
#else // WIN_VERSION
	int				err = 0;
	char			winpath[4096];
	char			winpath2[4096];
	char*			winpathfile = NULL;
	SHFILEOPSTRUCT	fileop;

	path_nameconform(s->s_name, winpath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
	strcat(winpath, "\\*");

	// This is exceedingly annoying: this string has to be double-terminated in order to work!
	winpath[strlen(winpath)] = 0;
	winpath[strlen(winpath)+1] = 0;

	fileop.hwnd = NULL;
	fileop.wFunc = FO_DELETE;
	fileop.pFrom = (LPCSTR)winpath;
	fileop.pTo = (LPCSTR)winpath;
	fileop.pTo = NULL;
	fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
	fileop.fAnyOperationsAborted = FALSE;

	// !!!
	// THE SUCCESS OF SHFILEOPERATION() SEEMS TO BE EXTREMELY INTERMITTENT
	// MULTIPLE CALLS TO THIS METHOD WILL EVENTUALLY RESULT IN SUCCESS
	// !!!
	err = SHFileOperation(&fileop);
	if(err)
		object_error((t_object *)x, "ERROR: %i deleting %s", err, winpath);
	else{
		winpath[strlen(winpath)-2] = 0;
		err = RemoveDirectory((LPCSTR)winpath);
		if(err == 0){
			err = GetLastError();
			object_error((t_object *)x, "ERROR: %i deleting the folder", err);
		}
	}
#endif
	object_obex_dumpout(x, _sym_bang, 0, NULL);
}
Example #2
0
void tap_folder_dounzip(t_folder *x, t_symbol *s, long argc, t_atom *argv)
{
	char	name[MAX_PATH_CHARS];

#ifdef MAC_VERSION
	char	script[MAX_PATH_CHARS + 200];
	char*	tempstr = NULL;
	t_atom	a;
	
	path_nameconform(s->s_name, name, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
	tempstr = strrchr(name, '/');
	if(!tempstr)
		return;
		
	*tempstr = 0;
	tempstr++;
	if(tempstr){
		snprintf(script, MAX_PATH_CHARS + 200, "do shell script \"cd \\\"%s\\\"; unzip %s\"", name, tempstr);
		atom_setsym(&a, gensym(script));
		object_method_typed(x->applescript, gensym("script"), 1, &a, NULL);
		object_method(x->applescript, _sym_bang);
	}
#else // WIN_VERSION
	; // TODO: what do we do here?
#endif
	object_obex_dumpout(x, _sym_bang, 0, NULL);
}
Example #3
0
void model_preset_filechanged(TTPtr self, char *filename, short path)
{
	WrappedModularInstancePtr	x = (WrappedModularInstancePtr)self;
	char 		fullpath[MAX_PATH_CHARS];		// path and name passed on to the xml parser
	char		posixpath[MAX_PATH_CHARS];
	TTValue		v;
	TTSymbol    current;
	t_atom		a;

	// get current preset
	EXTRA->presetManager->get("current", v);

	path_topathname(path, filename, fullpath);
	path_nameconform(fullpath, posixpath, PATH_STYLE_NATIVE, PATH_TYPE_BOOT);

	atom_setsym(&a, gensym(posixpath));
	defer_low(self, (method)model_preset_doread, gensym("read"), 1, &a);

    /* since JamomaMax#711 : we decide to mute the triggering of the current preset

    // try to recall last current preset
	current = v[0];
	atom_setsym(&a, gensym((char*)current.c_str()));
	defer_low((t_object*)x, (method)model_preset_dorecall, NULL, 1, &a);

    */
}
Example #4
0
void myCreateFolder(t_mkdir, t_symbol *newfoldername) 
// short CreateFolder(const FSRef parentFolder, const CFStringRef folderName) 
{
	OSErr myerr;
	long len;
	short path;
	char name[256];
	char inname[2048];
	char name[2048];
	char parentname[2048];
	FSSpec fs;
	CFStringRef str;
	CFURLRef url;
	HFSUniStr255 folderNameU;


	path_nameconform(inname, newfoldername->s_name, PATH_STYLE_NATIVE, PATH_TYPE_ABSOLUTE);	
	len = strlen(inname);
	strrchr();
	filename = strrchr(name, '/') + 1;

	if (!path_topathname(path, "", inname)) { // check if path alreay exists
	
		path_nameconform(outname, natname, PATH_STYLE_NATIVE, PATH_TYPE_ABSOLUTE);
		
		path_tospec(0, natname, &fs);
	
		str = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII);
		
		folderNameU.length = (UInt16) CFStringGetLength(str);
		
		CFStringGetCharacters(folderName, CFRangeMake(0, folderNameU.length), folderNameU.unicode);

		// see if it already exists?
		myerr = FSMakeFSRefUnicode(&parentname, folderNameU.length,folderNameU.unicode,
							kTextEncodingUnicodeDefault, NULL);
		// should now verify that is, in fact, a folder.
	
		if (myerr != noErr) { // no, so try to create it.		
			myerr = FSCreateDirectoryUnicode(&parentFolder, folderNameU.length, folderNameU.unicode,
				kFSCatInfoNone, NULL, NULL, NULL, NULL);
		}
		return myerr;	
	}
}
Example #5
0
void _filesys_get_path(t_filesys *x, const char* str_src, char *str_dest)
{
  char str_tmp[MAX_PATH_CHARS];

  if (_filesys_is_abs(x, str_src)) {
    strncpy_zero(str_tmp, str_src, MAX_PATH_CHARS); }
  else {
    strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
    strncat_zero(str_tmp, str_src, MAX_PATH_CHARS); }

  path_nameconform(str_tmp, str_dest, PATH_STYLE_NATIVE, PATH_TYPE_PATH);
}
Example #6
0
void model_preset_default(TTPtr self)
{
	WrappedModularInstancePtr	x = (WrappedModularInstancePtr)self;
	short		outvol;
	t_fourcc	outtype, filetype = 'TEXT';
	char 		fullpath[MAX_PATH_CHARS];		// path and name passed on to the xml parser
	char		posixpath[MAX_PATH_CHARS];
	t_atom		a;
	t_symbol*	textfile;

	if (x->patcherClass != kTTSymEmpty) {

        if (EXTRA->attr_presets != kTTSym_none) {

            textfile = gensym(EXTRA->attr_presets.c_str());
        }
		else if (x->patcherContext == kTTSym_model)
			jamoma_edit_filename(*ModelPresetFormat, x->patcherClass, &textfile);

		else if (x->patcherContext == kTTSym_view)
			jamoma_edit_filename(*ViewPresetFormat, x->patcherClass, &textfile);
		else
			return object_error((t_object*)x, "preset_default : can't get the context of the patcher");

		if (locatefile_extended((char*)textfile->s_name, &outvol, &outtype, &filetype, 1)) {
			//object_warn((t_object*)x, "preset_default : can't find %s file in the Max search path", textfile.data());
			return;
		}

		path_topathname(outvol, (char*)textfile->s_name, fullpath);
		path_nameconform(fullpath, posixpath, PATH_STYLE_NATIVE, PATH_TYPE_BOOT);

		atom_setsym(&a, gensym(posixpath));
		defer_low(self, (method)model_preset_doread, gensym("read"), 1, &a);

		// recall the default preset if exists
        atom_setsym(&a, gensym("default"));
		defer_low((t_object*)x, (method)model_preset_dorecall, NULL, 1, &a);

		// replace filewatcher
		if (EXTRA->filewatcher) {
			filewatcher_stop(EXTRA->filewatcher);
			object_free(EXTRA->filewatcher);
		}

		EXTRA->filewatcher = filewatcher_new((t_object*)x, outvol, (char*)textfile->s_name);
		filewatcher_start(EXTRA->filewatcher);
	}
	else
		object_error((t_object*)x, "preset_default : can't get the class of the patcher");
}
Example #7
0
t_max_err db_open(t_symbol *dbname, const char *fullpath, t_database **db)
{
	long	ac=0;
	t_atom	av[6];
	
	if (*db)
		object_free(*db);
	
	if (fullpath) {
		char	coercedpath[MAX_PATH_CHARS];
		short	err;
		char	dbpath[MAX_PATH_CHARS];
#ifdef MAC_VERSION
		char	*temppath;
#endif

		err = path_nameconform((char*)fullpath, coercedpath, PATH_STYLE_NATIVE_PLAT, PATH_TYPE_ABSOLUTE);
		if (err)
			strncpy_zero(coercedpath, fullpath, MAX_PATH_CHARS);
		
#ifdef MAC_VERSION
		temppath = strchr(coercedpath, ':');
		*temppath = '\0';
		temppath += 1;
		
		// at this point temppath points to the path after the volume, and coercedpath has the volume
		snprintf(dbpath, MAX_PATH_CHARS, "/Volumes/%s%s", coercedpath, temppath);
#else // WIN_VERSION
		strncpy_zero(dbpath, coercedpath, MAX_PATH_CHARS);
#endif
		
		atom_setsym(av+ac, gensym("@rambased"));
		ac++;
		atom_setlong(av+ac, 0);
		ac++;
		atom_setsym(av+ac, gensym("@filename"));
		ac++;
		atom_setsym(av+ac, gensym(dbpath));
		ac++;
	}
	atom_setsym(av+ac, gensym("@db"));
	ac++;
	atom_setsym(av+ac, dbname);
	ac++;
	
	*db = (t_database*)object_new_typed(_sym_nobox, _sym_sqlite, ac, av);
	if (!*db)
		return MAX_ERR_GENERIC;
	
	return MAX_ERR_NONE;
}
Example #8
0
void filesys_cd(t_filesys *x, t_symbol *sym)
{
  TRACE("filesys_cd");

  // Reset to the path containing the patcher file
  if (sym == gensym("~")) { _filesys_cd_patcher(x); }

  // ... or else set the path provided as an argument
  else {
    path_nameconform(sym->s_name, x->dir_s, PATH_STYLE_MAX, PATH_TYPE_ABSOLUTE);

    // If necessary add a closing slash character
    char *iter = x->dir_s + strlen(x->dir_s) - 1;
    if (*iter != '/') { *++iter = '/'; *++iter = '\0'; } }
}
Example #9
0
void _filesys_cd_patcher(t_filesys *x)
{
  // Get the top patcher containing the object
  t_object *patcher = NULL;
  object_obex_lookup(x, gensym("#P"), &patcher);
  patcher = jpatcher_get_toppatcher(patcher);
  
  // Initialize the current directory to the patcher filepath
  t_symbol *path = jpatcher_get_filepath(patcher);
  path_nameconform(path->s_name, x->dir_s, PATH_STYLE_MAX, PATH_TYPE_PATH);

  // Remove the patcher file name
  char *iter = x->dir_s;
  char *marker = x->dir_s;
  do { if (*iter == '/') { marker = iter; } } while (*iter++);
  *(marker + 1) = '\0';
}
Example #10
0
void filecontainer_gettemppath(t_filecontainer *x)
{
    char			temppath[512];
    char			outpath[512];
    t_symbol		*unique = symbol_unique();
    OSErr			err = 0;
#ifdef MAC_VERSION
    FSRef			folderref, newref;
    UniChar			uni[512];
    unsigned short	i;

    err = FSFindFolder(kUserDomain, kTemporaryFolderType, kCreateFolder, &folderref);
    err = FSRefMakePath(&folderref, (UInt8 *)temppath, 511);
    strcat(temppath, "/");
#else // WIN_VERSION
    GetTempPath(512, (LPSTR)temppath);
#endif
    strcat(temppath, unique->s_name);

#ifdef MAC_VERSION
    for(i=0; i<strlen(unique->s_name); i++)					// Convert from 8-bit ASCII to 16-bit Unicode
        uni[i] = unique->s_name[i];

    err = FSCreateDirectoryUnicode(&folderref, strlen(unique->s_name), uni,
                                   kFSCatInfoNone, NULL, &newref, NULL, NULL);
#else // WIN_VERSION
    CreateDirectory((LPCSTR)temppath, NULL);
#endif

    path_nameconform(temppath, outpath, PATH_STYLE_MAX, PATH_TYPE_ABSOLUTE);
    x->temp_fullpath = gensym(outpath);
    path_frompathname(outpath, &x->temp_path, temppath);	// re-using temppath since we don't need it anymore

    // Add to the searchpath
    path_addnamed(SEARCH_PATH, outpath, 1, 0);
}
Example #11
0
void folder_domakedir(t_folder *x, t_symbol *s, long argc, t_atom *argv)
{
	short	path = 0;				// parent folder, which we supply
	short	createdPath = 0;		// the new folder after it is created
	char	*folderName;			// the name of the new folder
	char	fullpath[4096];
	short	err = 0;
	char	temp[256];
	
	path_nameconform(s->s_name, fullpath, PATH_STYLE_MAX, PATH_TYPE_ABSOLUTE);
	folderName = strrchr(fullpath, '/');
	
	if (folderName) {
		*folderName = 0;
		folderName++;
		
		err = path_frompathname(fullpath, &path, temp);
		if (!err)
			err = path_createfolder(path, folderName, &createdPath);
		if (err)
			object_error((t_object*)x, "error %hd trying to create folder", err);
	}
	object_obex_dumpout(x, _sym_bang, 0, NULL);
}
Example #12
0
void filecontainer_doopen(t_filecontainer *x, t_symbol *arg)
{
    t_atom			a[4];
    int				err = 0;
    char			filename[256];
    short			path;
    t_fourcc		outtype = 0;
    t_fourcc		type = 'cO0p';
#ifdef MAC_VERSION
    char			*temppath;
    FSRef			ref;
    Boolean			isDir;
    FSCatalogInfo	catalogInfo;
#else // WIN_VERSION
    char			temppath[512];
#endif
    char			fullpath[512];
    t_object		*result = NULL;
    t_object		*result2 = NULL;
    char			**record = NULL;		// sqlite records
    char			**record2 = NULL;		// sqlite records
    t_filehandle	file_handle;
    t_ptr_size		len = 0;
    char			*blob;
    char			sql[512];

    if(!arg || !arg->s_name[0]) {
        if(open_dialog(filename, &path, &outtype, NULL, -1))			// Returns 0 if successful
            return;
    }
    else {
        t_fourcc typelist[1];
        typelist[0] = 'cO0p';
        strcpy(filename, arg->s_name);
        path = 0;
        locatefile_extended(filename, &path, &type, typelist, 0);
    }
    path_topotentialname(path, filename, fullpath, 0);
#ifdef MAC_VERSION
    temppath = strchr(fullpath, ':');
    temppath += 1;
#else // WIN_VERSION
    path_nameconform(fullpath, temppath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
#endif
    x->name = gensym(temppath);

    // Create our temp folder for extracted files
    filecontainer_gettemppath(x);

    // Create the SQLite instance
    atom_setsym(&a[0], gensym("@rambased"));
    atom_setlong(&a[1], 0);
    atom_setsym(&a[2], gensym("@db"));
    atom_setsym(&a[3], x->name);
    x->sqlite = object_new_typed(CLASS_NOBOX, _sym_sqlite, 4, a);

    // Operate on the open DB
    if(x->sqlite) {
        object_method(x->sqlite, ps_starttransaction);
        object_method(x->sqlite, _sym_execstring, TABLEDEF_FILES, NULL);
        object_method(x->sqlite, _sym_execstring, TABLEDEF_ATTRS, NULL);

        object_method(x->sqlite, _sym_execstring, "UPDATE files SET valid = 1", NULL);
        object_method(x->sqlite, _sym_execstring, "SELECT file_id, filename, moddate FROM files", &result);
        while(record = (char **)object_method(result, _sym_nextrecord)) {
            // Here we check for the optional 'platform' attr for this file.
            // If a flag exists for the other platform, but not for the current platform, then we ignore this file.
#ifdef MAC_VERSION
            sprintf(sql, "SELECT file_id_ext FROM attrs \
							WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]);
            object_method(x->sqlite, _sym_execstring, sql, &result2);
            record2 = (char **)object_method(result2, _sym_nextrecord);
            if(record2) {
                sprintf(sql, "SELECT file_id_ext FROM attrs \
								WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]);
                object_method(x->sqlite, _sym_execstring, sql, &result2);
                record2 = (char **)object_method(result2, _sym_nextrecord);
                if(!record2) {
                    sprintf(sql, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]);
                    object_method(x->sqlite, _sym_execstring, sql, NULL);
                    continue;
                }
            }
#else // WIN_VERSION
            snprintf(sql, 512, "SELECT file_id_ext FROM attrs \
							WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]);
            object_method(x->sqlite, _sym_execstring, sql, &result2);
            record2 = (char **)object_method(result2, _sym_nextrecord);
            if(record2) {
                snprintf(sql, 512, "SELECT file_id_ext FROM attrs \
								WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]);
                object_method(x->sqlite, _sym_execstring, sql, &result2);
                record2 = (char **)object_method(result2, _sym_nextrecord);
                if(!record2) {
                    snprintf(sql, 512, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]);
                    object_method(x->sqlite, _sym_execstring, sql, NULL);
                    continue;
                }
            }
#endif
            // At this point we have a file (record[0]), and we have determined that it is indeed a file we want to cache
            // So cache it to a new file in our temp path
            err = path_createsysfile(record[1], x->temp_path, type, &file_handle);
            if(err) {																// Handle any errors that occur
                object_error((t_object *)x, "%s - error %d creating file", filename, err);
            }
            else {
                snprintf(sql, 512, "SELECT content FROM files WHERE file_id = %s", record[0]);
                object_method(x->sqlite, ps_getblob, sql, &blob, &len);
                err = sysfile_write(file_handle, &len, blob);
                if(err) {
                    object_error((t_object *)x, "sysfile_write error (%d)", err);
                }
            }
            err = sysfile_seteof(file_handle, len);
            if(err) {
                object_error((t_object *)x, "%s - error %d setting EOF", filename, err);
            }
            sysfile_close(file_handle);		// close file reference
            sysmem_freeptr(blob);
            blob = NULL;

            // Set the moddate
#ifdef MAC_VERSION
//			FSCatalogInfo		catalogInfo;
//			Boolean             status;
            CFGregorianDate     gdate;
            CFAbsoluteTime      abstime;
            CFTimeZoneRef		tz;
            UTCDateTime			utc;

            sscanf(record[2], "%4ld-%02hd-%02hd %02hd:%02hd:%02lf", &gdate.year, (signed short*)&gdate.month, (signed short*)&gdate.day,
                   (signed short*)&gdate.hour, (signed short*)&gdate.minute, &gdate.second);
            tz = CFTimeZoneCopySystem();
            abstime = CFGregorianDateGetAbsoluteTime(gdate, tz);
            UCConvertCFAbsoluteTimeToUTCDateTime(abstime, &utc);
            catalogInfo.contentModDate = utc;

            strcpy(s_tempstr, x->temp_fullpath->s_name);
            temppath = strchr(s_tempstr, ':');
            temppath++;
            strcat(temppath, "/");
            strcat(temppath, record[1]);
            FSPathMakeRef((UInt8*)temppath, &ref, &isDir);
            err = FSSetCatalogInfo(&ref, kFSCatInfoContentMod, &catalogInfo);

#else // WIN_VERSION
            char				winpath[512];
            HANDLE				hFile;
            FILETIME			fileTime;
            SYSTEMTIME			systemTime;

            sscanf(record[2], "%4lu-%02lu-%02lu %02lu:%02lu:%02lu", &systemTime.wYear, &systemTime.wMonth, &systemTime.wDay,
                   &systemTime.wHour, &systemTime.wMinute, &systemTime.wSecond);
            err = SystemTimeToFileTime(&systemTime, &fileTime);

            strcpy(s_tempstr, x->temp_fullpath->s_name);
            path_nameconform(s_tempstr, winpath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
            strcat(winpath, "\\");
            strcat(winpath, record[1]);
            hFile = CreateFile((LPCSTR)winpath , GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
            if(hFile == INVALID_HANDLE_VALUE) {
                object_error((t_object *)x, "invalid handle value");
                goto out;
            }
            err = SetFileTime(hFile, &fileTime, &fileTime, &fileTime);
            if(err == 0) {
                err = GetLastError();
                object_error((t_object *)x, "Error setting date: %i", err);
            }
            CloseHandle(hFile);
out:
            ;
#endif
        }
        object_method(x->sqlite, ps_endtransaction);
    }
Example #13
0
void filesys_postdir(t_filesys *x)
{
  TRACE("filesys_posttdir");

  char str_tmp[MAX_PATH_CHARS];
  char str_cur[MAX_PATH_CHARS];

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_MAX, PATH_TYPE_ABSOLUTE);
  POST("PATH_STYLE_MAX / PATH_TYPE_ABSOLUTE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_ABSOLUTE);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_ABSOLUTE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_COLON, PATH_TYPE_ABSOLUTE);
  POST("PATH_STYLE_COLON / PATH_TYPE_ABSOLUTE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_SLASH, PATH_TYPE_ABSOLUTE);
  POST("PATH_STYLE_SLASH / PATH_TYPE_ABSOLUTE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
  POST("PATH_STYLE_NATIVE_WIN / PATH_TYPE_ABSOLUTE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_IGNORE);
  POST("PATH_STYLE_MAX / PATH_TYPE_IGNORE:  %s", str_cur);
  
  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_RELATIVE);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_RELATIVE:  %s", str_cur);
  
  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_BOOT);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_BOOT:  %s", str_cur);
  
  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_C74);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_C74:  %s", str_cur);
  
  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_PATH);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_PATH:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE, PATH_TYPE_DESKTOP);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_DESKTOP:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE_WIN, PATH_TYPE_TILDE);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_TILDE:  %s", str_cur);

  strncpy_zero(str_tmp, x->dir_s, MAX_PATH_CHARS);
  path_nameconform(str_tmp, str_cur, PATH_STYLE_NATIVE_WIN, PATH_TYPE_TEMPFOLDER);
  POST("PATH_STYLE_NATIVE / PATH_TYPE_TEMPFOLDER:  %s", str_cur);
  
  POST("Current directory:  %s", x->dir_s);
}
Example #14
0
static bool getmodulesub(const char *mod,char *dir,int len,const char *ext)
{
#if FLEXT_SYS == FLEXT_SYS_PD
    char *name;
    int fd = open_via_path("",mod,ext,dir,&name,len,0);
    if(fd >= 0) {
        fileclose(fd);
        FLEXT_ASSERT(name && *name);
    }
    else {
        // look for mod/__init__.py
        std::string tmp(mod); 
        int l = tmp.size();
        tmp += "/__init__";
        fd = open_via_path("",tmp.c_str(),ext,dir,&name,len,0);
        if(fd >= 0) {
            fileclose(fd);
            FLEXT_ASSERT(name && *name);

            // we must remove the module name from dir
            char *t = dir+strlen(dir)-l;
            FLEXT_ASSERT(!strcmp(mod,t) && t[-1] == '/');
            t[-1] = 0;
        }
        else
            name = NULL;
    }

    // if dir is current working directory... name points to dir
    if(dir == name) strcpy(dir,".");
    return name != NULL;
#elif FLEXT_SYS == FLEXT_SYS_MAX
    short path;
    long type;
    char smod[1024];
    strcpy(smod,mod);
    strcat(smod,ext);
    bool ok = !locatefile_extended(smod,&path,&type,&type,0);
    if(ok)
        // convert pathname to unix style
        path_topathname(path,NULL,smod);
    else {
        // do path/file.ext combinations work at all under Max?
        strcpy(smod,mod);

        short path;
        type = 'fold';
        ok = !locatefile_extended(smod,&path,&type,&type,1);
        if(ok) {
            // convert pathname to unix style (including trailing slash)
            path_topathname(path,NULL,smod);
            char *end = smod+strlen(smod);
            strcpy(end,mod);
            strcat(end,"/__init__");
            strcat(end,ext);

            // check if file is really existing: try to open it
            FILE *f = fopen(smod,"r");
            if(f) {
                *end = 0;  // clear module part ... we only need base path
                fclose(f);
            }
            else
                ok = false;
        }
    }
    
    if(ok) {
        // convert path into slash style needed for Python
#if 0
        // Max API function uses Volume:/Path notation
        path_nameconform(smod,dir,PATH_STYLE_SLASH,PATH_TYPE_ABSOLUTE);
#else
#if FLEXT_OS == FLEXT_OS_WIN
        char *colon = NULL;
#else
        char *colon = strchr(smod,':');
#endif
        if(colon) {
            *colon = 0;
            strcpy(dir,"/Volumes/");
            strcat(dir,smod);
            strcat(dir,colon+1);
        }
        else
            strcpy(dir,smod);
#endif
        return true;
    }
    else
        // not found
        return false;
#else
#pragma message("Not implemented");
    return false;
#endif
}