App_Scriptpath contains wrong path in certain cases
issueid=396 19-04-2013 13:30
thinBasic MVPs
Number of reported issues by ReneMiner: 83
App_Scriptpath contains wrong path in certain cases

I tried to open some to my program associated files
It works.

But:
App_Scriptpath holds/returns not the path of my App (.exe) - instead it holds the path where the file to open is located.
That messes up all subfolder-locations that my script is supposed to work with.

Attachement contains example thinBaisc-Source + bundled exe + subfolder with some file to open by rightclick, choose app_ScriptpathTest.exe to open the .XXX123- file for a test.

this is the Main-Scripts code, so you can imagine what awaits you:
	
'---------------------------------------------------------
' YOU READ THE CODE OF app_ScriptpathTest.tBasic
' Test to OS_Command(s)
 
Uses "Console", "OS", "FILE"
 
 
#INCLUDE "Scriptpath2.tBasicU"
 
Function TBMain()
 
Local sFile As String
 
  PrintL "This is App_Scriptpath:"
  PrintL APP_ScriptPath 
  PrintL "-----------------------"
 
  If OS_GetCommands >= 2 Then
    sFile = Mid$(OS_GetCommand(2), 2, Len(OS_GetCommand(2)) - 2)
    PrintL "This is OS_Command(2)-Parameter without quotes:"
    PrintL sFile
    PrintL "-------------------------------------------------------------"
    PrintL "Press any key to continue"
    PrintL "."
    PrintL "."
    PrintL "."
    WaitKey
     
    ShowTextFile(sFile)
  EndIf
 
  PrintL "Press any key again to End"
 
  WaitKey  
 
End Function  
 
' END OF CODE
'------------------------------------------------------
'follows second unit

'this is just the dummy-include with some sub, so we have a real bundle

Sub ShowTextFile(ByVal sFile As String)
 
Local fNum As DWord
 
fNum = FILE_Open(sFile, "INPUT")
If fNum Then   
  PrintL "This is File-Content of associated file:"
  PrintL "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  PrintL "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  While Not FILE_EOF(fNum)
    PrintL FILE_LineInput(fNum)
  Wend
  PrintL "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  PrintL "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  FILE_Close(fNum)
EndIf
 
 
End Sub
If run this from thinAir it will show the main-script- but that's not the intention.
So I added in the subfolder some simple textfile with special file-extension .XXX123

leave the textfile in subfolder otherwise you won't see if app_scriptpath is wrong (which you get displayed on first console-printout)
rightclick the .XXX123-file and select "app_ScriptPathTest.exe" to open it - check which App_Scriptpath console shows.

btw. I use 1.9.5.0 but the options-list does not offer this so I had to choose 1.9.2.0 as affected version
Issue Details
Issue Number 396
Project thinBasic
Category Core engine (thinCore.dll)
Status Fixed
Priority 3
Affected Version 1.9.2
Fixed Version 1.9.6
Milestone (none)
Users able to reproduce bug 1
Users unable to reproduce bug 0
Assigned Users (none)
Tags (none)




19-04-2013 16:03
Super Moderator
Hi Rene,

I can confirm the behavior on my PC, it seems like a bug to me.


Petr

20-04-2013 16:30
thinBasic MVPs
(Please read post on top first)

Just one quick- has nothing to do with this bug but I experienced when I tried to create this bundle:

The second unit was named "app_scriptpath[something - I don't know any more].tBasicU" before.

So I post this here because the attached file is the perfect testing-object - just do some little change in it:

Try out, rename/save the second unit as "app_scriptpath.tBasicU", change the #include-line in main-unit too and create bundle then. You'll experience a lot of different behaviour ->Error(3), Error(4) - sometimes succesful but .exe does not work at all, sometimes .exe does not start when associated file is clicked, sometimes (with no changes in the meantime!) the exe can not be started because of invalid header, sometimes because of unknown keyword as "PrintL" or "Function" etc. - lot of funny stuff, just because units filename STARTS WITH tB-keyword. The (sometimes) succesful created bundles have different length and behave different -from exactly same base-material!
I have impression creation of bundle fails if an units (or .dll name) starts with tB-Keyword (seems not to apply to main-unit) and I think there is some string-pointer-thing somewhere - otherwise it would always behave in the same manner.

Edit: I have to admit, I don't know the exact filename I used any more. But can very well be it was "app_ScriptpathTest.tBasicU" (same as Main-Unit)

21-04-2013 12:01
thinBasic author
The problem seems related to OS_GetCommands and OS_GetCommand and not to App_ScriptPath.
OS_GetComm... behave differently when used from a script executed from thinAir or script executed from Shell or script executed from bundled exe

21-04-2013 12:17
thinBasic author
If you avoid to use any OS_... command like the following, is it correct or still wrong path?
...
Function TBMain()


Local sFile As String


  PrintL "This is App_Scriptpath:"
  PrintL APP_ScriptPath  
  PrintL "-----------------------"


  'If OS_GetCommands >= 1  Then 
    sFile = APP_ScriptPath & APP_ScriptName 'Mid$(OS_GetCommand(2), 2, Len(OS_GetCommand(2)) - 2)
    'PrintL "This is OS_Command(2)-Parameter without quotes:"
    PrintL sFile
    PrintL "-------------------------------------------------------------" 
    PrintL "Press any key to continue"
    PrintL "."
    PrintL "."
    PrintL "."
    WaitKey
    
    ShowTextFile(sFile)
  'EndIf


  PrintL "Press any key again to End"


  WaitKey   


End Function   
...

21-04-2013 12:20
thinBasic MVPs
(I removed Uses "OS" also)
still wrong app_scriptpath : holds the folder of associated file but not location of exe

Other try (bundle in isolation-mode) resultet with some \temp-folder inside \Subfolder as app_scriptpath

21-04-2013 12:34
thinBasic author
Sorry Rene, maybe it's me and my brain not working as expected (I'm not feeling good in the last 3 days) but there is something I do not understand.

APP_ScriptPath is supposed to return:
  1. the path of the script been executed when script is executed from thinAir or shell
  2. the path of the EXE when script is bundled into an EXE without "Activate Isolation" is off in bundled options
  3. the temporary path of the script when "Activate Isolation" is on in bundled options


Option 3 is (or can) be wrong. There should be an option or a new command telling which path you want.

But option 1 and 2 should work as expected. In my tests App_ScriptPath always return the full script path.
I placed source script and bundled exe into directory "C:\thinBasic\SampleScripts\_xBugs\APP_ScriptPath\" and App_ScriptPath always returns "C:\thinBasic\SampleScripts\_xBugs\APP_ScriptPath\"

21-04-2013 12:37
thinBasic MVPs
the problem is the following: as long as I start the exe directly - app_scriptpath holds the path where the exe is located. That's correct.
But if I try to open another file (a document) with my exe - app_scriptpath holds not the path of the exe but the path of the file I tried to open.

So my exe (that might have some subfolders asides) does not find these needed folders any more because they're not present in the location of what app_scriptpath returns because that is the associated-documents-path and not the path where the exe is located

Did you download attachement and tried to open the .xxx123-file from \subfolder with the app_scriptpathTest.exe?

I really can't describe any better :(

21-04-2013 13:37
thinBasic author
Rene,

I'm not able to replicate the problem. In all cases I tested, APP_SourcePath returns the path of the source or the Exe in case of Bundled Exe without "Isolation"
I'm still thinking the problem is inside OS_GetCommand..s and not inside App_SourcePath

Can you create a script showing the problem but without using OS commands?
Below my example that I have used both as source and as bundled Exe and all seems working fine.


'---------------------------------------------------------' YOU READ THE CODE OF app_ScriptpathTest.tBasic


Uses "Console","FILE"




#INCLUDE "Scriptpath2.tBasicU"


Function TBMain()


Local sFile As String


  PrintL "This is App_Scriptpath:"
  PrintL APP_ScriptPath  
  PrintL "-----------------------"


    sFile = APP_ScriptPath & "SubFolder\appTestText.xxx123"
    PrintL sFile
    PrintL "-------------------------------------------------------------" 
    PrintL "Press any key to continue"
    PrintL "."
    PrintL "."
    PrintL "."
    WaitKey
    
    ShowTextFile(sFile)


  PrintL "Press any key again to End"


  WaitKey   


End Function   


' END OF CODE
'------------------------------------------------------

21-04-2013 13:42
thinBasic MVPs
Uses "Console"  

PrintL "App_Scriptpath:"
PrintL APP_ScriptPath

WaitKey
make bundle,
select any file from your hard-drive (that is not an executable and in a different folder than the just made bundle) rightclick, open with - choose the just made bundled exe to open the other file.

21-04-2013 13:55
Super Moderator
Nice minimal example, I can see it on my PC, here description:
  • I create EXE as "D:\util\test\test.exe"
  • I run the bundled EXE, it prints "D:\util\test\" - correct!
  • I press key to close the script


But, if I start the script by dragging the file to EXE, it misbehaves. To give illustrated example:


  • I drag file "d:\util\myFile.txt" to the bundled EXE
    • bundled EXE starts
    • APP_ScriptPath returns "D:\util\" - wrong, I would expect "D:\util\test\" again


According to help file, it should behave as:
APP_ScriptPath = File_PathSplit(APP_ScriptFullName, %Path_RootPath)
...but it behaves like:
APP_ScriptPath = DIR_CurrentPath

Petr

21-04-2013 14:11
thinBasic author
OK, sorry: as supposed it was my brain not to understand.

I got the problem, I'm checking about a solution

21-04-2013 17:20
thinBasic MVPs
I tried Petr's Syntax
mySafeScriptpath = File_PathSplit(APP_ScriptFullName, %Path_RootPath)
but this returns the wrong path too!

22-04-2013 17:47
Super Moderator
Aha,

strange, but you are right Renne, just tried it and even my approach is not helping.


Petr

28-04-2013 22:12
thinBasic author
Can you please download 1.9.6 from http://www.thinbasic.biz/projects/th...ic_1.9.6.0.zip
and see if now it works?

I will wait for your reply before publishing 1.9.6

29-04-2013 11:05
thinBasic MVPs
Now works correct, - I had a few problems making bundle- but after a re-boot it's all fine now. Does not create folders at wrong locations no more, opens associated files- all as expected :)

30-04-2013 07:13
thinBasic author
Good.

It took one day of debugging to find the problem.
I had to change almost the complete logic of the stub exe bundled into thinBasic executables.
It was using current directory to exttract some files from bundled exe. When you drag and drop a file into an EXE, the operating system pass as "current directory" the directory of the file dragged and not the directory where the executable resides.

I will fix some other points and then release 1.9.6

+ Reply