[Vm-dev] [commit][2689] updated Scratch plugin code to get user home path right whether the image is run from inside !Scratch or normally

commits at squeakvm.org commits at squeakvm.org
Sun Feb 17 23:05:56 UTC 2013


Revision: 2689
Author:   rowledge
Date:     2013-02-17 15:05:55 -0800 (Sun, 17 Feb 2013)
Log Message:
-----------
updated Scratch plugin code to get user home path right whether the image is run from inside !Scratch or normally

Modified Paths:
--------------
    trunk/platforms/RiscOS/plugins/ScratchPlugin/sqRPCScratchOps.c

Modified: trunk/platforms/RiscOS/plugins/ScratchPlugin/sqRPCScratchOps.c
===================================================================
--- trunk/platforms/RiscOS/plugins/ScratchPlugin/sqRPCScratchOps.c	2013-02-16 01:30:41 UTC (rev 2688)
+++ trunk/platforms/RiscOS/plugins/ScratchPlugin/sqRPCScratchOps.c	2013-02-17 23:05:55 UTC (rev 2689)
@@ -22,7 +22,9 @@
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
+// #define DEBUG
 
+#include "sq.h"
 #include "ScratchPlugin.h"
 #include <stdlib.h>
 #include <string.h>
@@ -51,21 +53,32 @@
 	//  5 - user's music folder
 	// path is filled in with a zero-terminated string of max length maxPath
 	// RISC OS really doesn't do things this way but let's see if it works out
-extern char * getImageName();
+extern char * getImageName(void);
+extern void sqStringFromFilename( char * sqString, char*fileName, int sqSize);
+extern char * getAttributeString(sqInt id) ;
+char * vmPath = getAttributeString(0);
 char * imageName = getImageName();
-extern void sqStringFromFilename( char * sqString, char*fileName, int sqSize);
+	if ((imageName == NULL) || (strlen(imageName) == 0)) return;
+
 	int imagePathLen = strrchr(imageName, '.') - imageName;
+	PRINTF(("GetFolderPathForID: vmPath: %s ln: %d\n", vmPath, strlen(vmPath)));
+	PRINTF(("GetFolderPathForID: image path: %s ln: %d\n", imageName, imagePathLen));
 
-	char *s = NULL;
-
 	path[0] = 0;  // a zero-length path indicates failure
 
-	// get the scratch image's directory
-	s = getImageName();
-	if ((s == NULL) || (strlen(s) == 0)) return;
+	// convert the RISC OS string to a Squeak format string
+	sqStringFromFilename(path, imageName, imagePathLen);
 
-	strncat(path, s, imagePathLen -1); // home folder
+	// if the path is the same as the vmPath we need
+	// to go up one more level since that implies we are using an image
+	// within a !Scratch application bundle
+	if (strncmp(vmPath, imageName, imagePathLen -1) == 0) {
+		PRINTF(("paths equal, chop image path back\n"));
+		*strrchr(path, '/') = NULL;
+	}
+	PRINTF(("GetFolderPathForID: final image path: %s ln: %d\n", path, imagePathLen));
 
+
 	if (folderID == 1) return;
 	if (folderID == 2) strncat(path, "/Desktop", maxPath);
 	if (folderID == 3) strncat(path, "/Documents", maxPath);



More information about the Vm-dev mailing list