Posted: 10th Jun 2021 11:03
Hi,
I was wondering is it possible to for example create an image viewer, where you can choose on windows "open file with..." and open an image with my viewer.
how to get the path in code? and is it even possible?

ps: I'm using tier 1 agk classic
Posted: 10th Jun 2021 13:30
Yes
the built in file handling commands https://www.appgamekit.com/documentation/Reference/File.htm
the built in image handling commands https://www.appgamekit.com/documentation/Reference/Image.htm

and if your still after more file handling commands https://forum.thegamecreators.com/thread/219478
Posted: 10th Jun 2021 15:12
Thank you. But I didn't found any function that would return file path string from "open file with" command. Maybe I'm missing something.
Posted: 10th Jun 2021 15:37
using FileExplore as suggested, see: FileExplore.GetCL() - (aka, "GetCommandLine" arguments )

when the image is sent to your App via "Open with", that command will return the absolute path of the image, among other things, separated by pipes "|".

1) Parse the string returned by GetCL (see Token commands), 2) find the path, 3) load the image/sprite

i have similar on another machine but i stuck it in the "Send To" queue vs "Open With".
Posted: 10th Jun 2021 16:36
Thank you, it works
Posted: 10th Jun 2021 17:01
care to share the code? i meant to do an image viewer myself. the other project handles txt files/is more convoluted.
Posted: 10th Jun 2021 18:10
sure, I'll post it when it's done
Posted: 10th Jun 2021 20:36
It sure is allot easier with file explorer as it makes allot of things easier but not impossible without
for example
+ Code Snippet
function ChooseFile()

        local spr

        ret$=ChooseRawFile("*.jpg;*.png")
        if ret$=""
                spr = CreateSprite(0)
        else

                spr = LoadSprite(ret$)

        endif

        SetSpriteDepth(spr,20)
        SetSpriteSize(spr,-1.0,GetVirtualHeight())
        SetSpritePosition(spr,0,0)

endfunction spr

in the above snippet the ret$ holds the full path of the file it just also includes the file itself so its a matter of just removing whats not needed from the right of the string
ps ret$ may need to be global or passed by reference to use the code above

for example
+ Code Snippet
function trimPath(str$ as string)
	num as integer:num2 as integer
	
num=len(str$):trimstr$ as string
if num<1 then exitfunction ""
repeat
    dec num
until mid(str$,num,1)="\"
for num2=(num+1) to len(Str$)   
    trimStr$=trimStr$+mid(str$,num2,1) 
next
endfunction trimStr$


it could also be done much more efficiently with https://www.appgamekit.com/documentation/Reference/Core/GetStringToken.htm

As much as i love the use of plugins i refrain from them when i dont have to use them but there are some great ones around and madbit certainly has produced some great plugins
Posted: 10th Jun 2021 20:45
@fubarpk, how are you getting the path wtihout a dll? the parsing is raltively easy after that.
Posted: 10th Jun 2021 20:51
from memory it was just a matter of the above and then loadImage("raw:"+ret$+img)
let me make a test proggy or find one of ,one of my examples i used that in, ive since replaced the code with file explorer just because it was cleaner and already was using Nuklear
so seemed no point avoiding dlls
Posted: 10th Jun 2021 21:02
the bare bones placement editor on this thread https://forum.thegamecreators.com/thread/222027?page=3 used that approach
a bit of string handling but yes doable not very clean code as such

certainly allot cleaner with madbits fileexplorer a snippet example from krazy grandprix editor
+ Code Snippet
global cd_tlEdit as string:cd_tlEdit=fileExplore.getWorkingDirectory()
fileExplore.setWorkingDirectory("..\")

.
.
.
LoadImage ("raw:"+cd_tlEdit+"\media\"+"environment\startfinish.png")
Posted: 10th Jun 2021 21:12
i'm only seeing selecting/choosing a file in your code. that's not the issue.

we want to right-click on an image in any folder (via windows native), and use Open With (an AppGameKit app) to view it.

create an image viewer, where you can choose on windows "open file with..." and open an image with my viewer.


somewhere i have a proggy that i wrote that would load .txt files this way. up to 10 at a time, i believe (i think that was a limit madbit set).
Posted: 10th Jun 2021 21:28
Apologies i misunderstood

I understand we have this command RunApp( szFilename, szParameters ) so the parameters of an app should be able to be read
but no idea how as they would have to be passed from windows when you chose open with ide have to do tests on that myself
I always thought that was more of a tier2 thing in the past.
Posted: 10th Jun 2021 21:43
I've managed to do it with the GetCL() function

+ Code Snippet
#import_plugin FileExplore

Fileee$ = FileExplore.GetCL()

F1$=GetStringToken( Fileee$, "|", 2 )
F2$=left(F1$,len(F1$)-1)
F3$=right(F2$,len(F2$)-1)

SetErrorMode(2)



SetWindowTitle( "Viewer Prototype" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) 

SetVirtualResolution( 1024, 768 ) 
SetOrientationAllowed( 1, 1, 1, 1 ) 
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 ) 
UseNewDefaultFonts( 1 ) 

do
 
    print(Fileee$)
    
    Sync()
loop



this code will print the path of the file you "open with" or you can even drag a file on an exe
Posted: 11th Jun 2021 0:30
weird. are you loading the image at all? im getting an error trying to load the image with what you have (it shows the correct path in the error...).
this:
+ Code Snippet
#import_plugin FileExplore

File$ = FileExplore.GetCL()
F1$=GetStringToken( File$, "|", CountStringTokens(File$,"|")  )

SetErrorMode(2)

SetWindowTitle( "Viewer Prototype" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) 

SetVirtualResolution( 1024, 768 ) 
SetOrientationAllowed( 1, 1, 1, 1 ) 
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 ) 
UseNewDefaultFonts( 1 ) 

do
	`LoadImage(Fileee$)
    print(F1$)
    If GetPointerPressed() then OpenBrowser(F1$)
    `if GetPointerPressed() then LoadSprite("raw:" + F1$)
    Sync()
loop

...[s]will send it to the browser but[/s] won't load it as a sprite.

i tried multiple variations of directory settings (AGK & FileExplore), even tried reading it byte by byte.

edit: not the browser, to the Photos app (default image viewer) which, to me, says its just launching the file and letting windows decide how to open it. but, it obviously knows where the file it but can't load it as an image or otherwise (will launch just about any fiietype).
Posted: 11th Jun 2021 2:56
@Virtualnomad have you tried string SimplifyPath( szPath ) it may not be the issue but a command i have learnt helps with compatability
Posted: 11th Jun 2021 4:56
I have been asked to provide assistance here.
As I understand it, you want to open and display the image by dragging an image file onto the AppGameKit executable app.
Is that correct?

If it is, then I have taken the code from 'jakubkwiatkowski' as a basis. Didn't miss much more to reach the goal.

I hope this helps.

+ Code Snippet
#import_plugin FileExplore

Fileee$ = FileExplore.GetCL()

F1$=GetStringToken( Fileee$, "|", 2 )

SetErrorMode(2)

SetWindowTitle( "Viewer Prototype" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) 

SetVirtualResolution( 1024, 768 ) 
SetOrientationAllowed( 1, 1, 1, 1 ) 
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 ) 
UseNewDefaultFonts( 1 ) 

LoadSprite(1, "raw:"+F1$)

do
    print(Fileee$)
    print(F1$)
    
    Sync()
loop


EDIT:
@Virtual Nomad
Your code works for me too.
Posted: 11th Jun 2021 5:52
Your code works for me too.

but, it doesn't work.

we're trying to open an image via the Open With windows dialogue.

the app has the path but LoadSprite "can't find" it.

using your code:
Posted: 11th Jun 2021 6:23
I have tested it by dragging the image to the exe.
The way you do it does not work because the path is in quotes ' " '.
Remove these then it should work.
Posted: 11th Jun 2021 6:54
I tested what madbit suggested and got it working like this by right clicking an image the opening the browser failed for me with classic
+ Code Snippet
#import_plugin FileExplore

File$ = FileExplore.GetCL()
F1$=GetStringToken( File$, "|", CountStringTokens(File$,"|")  )

SetErrorMode(2)

SetWindowTitle( "Viewer Prototype" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) 

SetVirtualResolution( 1024, 768 ) 
SetOrientationAllowed( 1, 1, 1, 1 ) 
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 ) 
UseNewDefaultFonts( 1 ) 
F1$=(trimQuotes(F1$))
createSprite(loadimage("raw:"+F1$))
do
	//`LoadImage(Fileee$)
    
    //If GetPointerPressed() then OpenBrowser(trimQuotes(F1$))
    //if GetPointerPressed() then LoadSprite("raw:" + F1$)
    Sync()
loop

function trimQuotes(fileStr as string)
	fileStr=GetStringToken( Filestr,chr(34), CountStringTokens(Filestr,chr(34))  )
endfunction fileStr