History

fixed chugin macOS bundle loading

Ge Wang committed 3 years ago

Commit daf21e31 parent 42a3f433 files · +138 −43Browse files

Showing the changes to src/core/util_string.cpp (1 of 3 files). Show all

Unified · Split

src/core/util_string.cpp+74−27
@@ -495,7 +495,7 @@ std::string get_full_path( const std::string & fp ) · 494 unmodified lines
495495 char * result = realpath(fp.c_str(), buf);
496496
497497 // try with .ck extension
498− if(result == NULL && !str_endsin(fp.c_str(), ".ck"))
498+ if( result == NULL && !extension_matches(fp, ".ck") )
499499 result = realpath((fp + ".ck").c_str(), buf);
500500
501501 if(result == NULL)
@@ -514,7 +514,7 @@ std::string get_full_path( const std::string & fp ) · 12 unmodified lines
514514 #endif
515515
516516 // try with .ck extension
517− if(result == 0 && !str_endsin(fp.c_str(), ".ck"))
517+ if( result == 0 && !extension_matches(fp, ".ck") )
518518 {
519519 #ifndef __CHUNREAL_ENGINE__
520520 result = GetFullPathName((fp + ".ck").c_str(), MAX_PATH, buf, NULL);
@@ -687,21 +687,6 @@ std::string normalize_directory_separator( const std::string & filepath ) · 166 unmodified lines
687687
688688
689689
690−//-----------------------------------------------------------------------------
691−// name: str_endsin()
692−// desc: return true if the first string ends with the second
693−//-----------------------------------------------------------------------------
694−t_CKBOOL str_endsin( const char * str, const char * end )
695−{
696− size_t len = strlen(str);
697− size_t endlen = strlen(end);
698−
699− return strncmp(str+(len-endlen), end, endlen) == 0;
700−}
701−
702−
703−
704−
705690 //-----------------------------------------------------------------------------
706691 // name: is_absolute_path()
707692 // desc: return true if path names an absolute path on the underlying platform
@@ -730,23 +715,85 @@ t_CKBOOL is_absolute_path( const std::string & path ) · 22 unmodified lines
730715
731716 //-----------------------------------------------------------------------------
732717 // name: extension_matches()
733−// desc: check whether a filename matches a particular extension
718+// desc: test whether a filename ends in a particular extension
734719 //-----------------------------------------------------------------------------
735−t_CKBOOL extension_matches( const std::string & filename, const std::string & extension )
720+t_CKBOOL extension_matches( const std::string & filename,
721+ const std::string & extension,
722+ t_CKBOOL ignoreCase )
736723 {
737− // lowercase
738− string f = tolower( filename );
739− string e = tolower( extension );
724+ // if ignore case, lower case both
725+ string f = ignoreCase ? tolower(filename) : filename;
726+ string e = ignoreCase ? tolower(extension) : extension;
740727 // look for extension from the end
741728 std::size_t pos = f.rfind( e );
742729 // check result
743730 return (pos != std::string::npos) && (pos == (f.length()-e.length()));
731+}
732+
733+
744734
745− // t_CKUINT extension_length = strlen( extension );
746− // t_CKUINT filename_length = strlen( filename );
747− //
748− // return strncmp( extension, filename+(filename_length-extension_length),
749− // extension_length ) == 0;
735+
736+//-----------------------------------------------------------------------------
737+// name: extension_removed()
738+// desc: return filename without extension
739+//-----------------------------------------------------------------------------
740+std::string extension_removed( const std::string & filename,
741+ const std::string & extension,
742+ t_CKBOOL ignoreCase )
743+{
744+ // if ignore case, lower case both
745+ string f = ignoreCase ? tolower(filename) : filename;
746+ string e = ignoreCase ? tolower(extension) : extension;
747+ // look for extension from the end
748+ std::size_t pos = f.rfind( e );
749+ // no match, return original
750+ if( pos == std::string::npos ) return filename;
751+ // return substring
752+ return filename.substr( 0, pos );
753+}
754+
755+
756+
757+
758+//-----------------------------------------------------------------------------
759+// name: subdir_ok2recurse()
760+// desc: test if a directory name is OK to recurse, e.g., in search for chugins
761+// the reason we have this function is for macOS bundles that are actually
762+// directories, e.g., if Faust.chug is directory and the actual chugin
763+// is located in side in /Contents/MacOS -- in which case we would not
764+// search for more chugins within the Faust.chug directory;
765+// HOWEVER, something like .chug (a directory name starting with '.') is
766+// okay, as that could be hidden directory
767+//-----------------------------------------------------------------------------
768+t_CKBOOL subdir_ok2recurse( const std::string & dirName,
769+ const std::string & extension,
770+ t_CKBOOL ignoreCase )
771+{
772+ // if ignore case, lower case both
773+ string f = ignoreCase ? tolower(dirName) : dirName;
774+ string e = ignoreCase ? tolower(extension) : extension;
775+ // if the two are equal, e.g., ".chug". OK
776+ if( f == e ) return TRUE;
777+
778+ // return the opposite of extension matches
779+ // i.e., if extension matches, don't recurse
780+ return !extension_matches( dirName, extension, ignoreCase );
781+}
782+
783+
784+
785+
786+//-----------------------------------------------------------------------------
787+// name: str_endsin()
788+// desc: return true if the first string ends with the second
789+// *** CURRENTLY NOT USED; see extension_matches() ***
790+//-----------------------------------------------------------------------------
791+t_CKBOOL str_endsin( const char * str, const char * end )
792+{
793+ size_t len = strlen(str);
794+ size_t endlen = strlen(end);
795+
796+ return strncmp(str+(len-endlen), end, endlen) == 0;
750797 }
751798
752799

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t