Author Topic: Need ideas for more API usage....  (Read 3993 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Need ideas for more API usage....
« on: September 23, 2020, 11:29:53 pm »
Fellas, I need more ideas for API usage. Whether it be WinAPI or REST/HTTP/HTTPS. Just some ideas. I'm getting restless waiting at home for call backs for jobs I've been applying to so I'm keeping myself occupied by absorbing myself into QB64. Give me some ideas, bros.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need ideas for more API usage....
« Reply #1 on: September 23, 2020, 11:59:31 pm »
For moving copying deleting... files something to do them in groups selected out of various folders and placed into a shopping cart then at checkout time do the function. I think moving files or copying for backup into one folder is what I have in mind. For instance I'd like to backup all QB64 folders without the exe's to save a ton of room.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Need ideas for more API usage....
« Reply #2 on: September 24, 2020, 12:09:37 am »
So I could basically just build an array with the files that you are wanting to move and then move them to the specified directory? And I guess for the backup thing it would be like a scheduled task? I'll look into this.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Need ideas for more API usage....
« Reply #3 on: September 24, 2020, 12:27:29 am »
@bplus Here is something I did just now....

Code: QB64: [Select]
  1. DIM cart(5) AS STRING
  2. cart(1) = _DIR$("desktop") + "QB64 x64\GetComputerName.bas"
  3. cart(2) = _DIR$("desktop") + "QB64 x64\timediff.bas"
  4. cart(3) = _DIR$("desktop") + "QB64 x64\qrtag api.bas"
  5. cart(4) = _DIR$("desktop") + "QB64 x64\Genderize API.bas"
  6. cart(5) = _DIR$("desktop") + "QB64 x64\rewind.png.MEM"
  7.  
  8. dest = _DIR$("desktop")
  9.  
  10. a = RunTransaction(cart(), dest, 2)
  11.  
  12. FUNCTION RunTransaction (filecart() AS STRING, dest AS STRING, mode AS INTEGER) 'dest is optional, only used for Copy and Move
  13.     DIM x AS INTEGER
  14.     DIM a AS INTEGER
  15.     IF RIGHT$(dest, 1) <> "\" THEN
  16.         dest = dest + "\"
  17.     END IF
  18.     SELECT CASE mode
  19.         CASE 1 'Recycle
  20.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  21.                 IF filecart(x) <> "" THEN
  22.                     a = Recycle(filecart(x))
  23.                 END IF
  24.             NEXT
  25.         CASE 2 'Copy
  26.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  27.                 IF filecart(x) <> "" THEN
  28.                     a = Copy(filecart(x), dest + StripDirectory(filecart(x)))
  29.                 END IF
  30.             NEXT
  31.         CASE 3 'Move
  32.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  33.                 IF filecart(x) <> "" THEN
  34.                     a = Move(filecart(x), dest + StripDirectory(filecart(x)))
  35.                 END IF
  36.             NEXT
  37.     END SELECT
  38.  
  39. FUNCTION StripDirectory$ (OFile$)
  40.     DO
  41.         OFile$ = RIGHT$(OFile$, LEN(OFile$) - INSTR(OFile$, "\"))
  42.     LOOP WHILE INSTR(OFile$, "\")
  43.     StripDirectory$ = OFile$
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need ideas for more API usage....
« Reply #4 on: September 24, 2020, 12:37:17 am »
hmm... maybe not enough of a challenge.

I realized I could write the backup thing with QB64, I'm pretty sure, specially after we were doing trees of our files.

I would like to write a QB64 program, compile it and run it in shell from same program that wrote the program.
I don't know if API can help with that? What do you think?


Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Need ideas for more API usage....
« Reply #5 on: September 24, 2020, 01:02:47 am »
@bplus
Here are screenshots from a tweak I made to the transaction thing. It can be used for your backup idea.

  [ You are not allowed to view this attachment ]    [ You are not allowed to view this attachment ]    [ You are not allowed to view this attachment ]  

Code: QB64: [Select]
  1.  
  2. 'To - From, From - To Flags
  3. CONST FO_MOVE = &H1
  4. CONST FO_COPY = &H2
  5. CONST FO_DELETE = &H3
  6. CONST FO_RENAME = &H4
  7.  
  8. 'File Op Flags
  9. CONST FOF_MULTIDESTFILES = &H1
  10. CONST FOF_CONFIRMMOUSE = &H2
  11. CONST FOF_SILENT = &H4
  12. CONST FOF_RENAMEONCOLLISION = &H8
  13. CONST FOF_NOCONFIRMATION = &H10
  14. CONST FOF_WANTMAPPINGHANDLE = &H20
  15. CONST FOF_ALLOWUNDO = &H40
  16. CONST FOF_FILESONLY = &H80
  17. CONST FOF_SIMPLEPROGRESS = &H100
  18. CONST FOF_NOCONFIRMMKDIR = &H200
  19. CONST FOF_NOERRORUI = &H400
  20. CONST FOF_NOCOPYSECURITYATTRIBS = &H800
  21. CONST FOF_NORECURSION = &H1000
  22. CONST FOF_NO_CONNECTED_ELEMENTS = &H2000
  23. CONST FOF_WANTNUKEWARNING = &H4000
  24. CONST FOF_NORECURSEREPARSE = &H8000
  25. CONST FOF_NO_UI = FOF_SILENT
  26.  
  27. 'Return Values
  28. CONST DE_SAMEFILE = &H71
  29. CONST DE_MANYSRC1DEST = &H72
  30. CONST DE_DIFFDIR = &H73
  31. CONST DE_ROOTDIR = &H74
  32. CONST DE_OPCANCELLED = &H75
  33. CONST DE_DESTSUBTREE = &H76
  34. CONST DE_ACCESSDENIEDSRC = &H78
  35. CONST DE_PATHTOODEEP = &H79
  36. CONST DE_MANYDEST = &H7A
  37. CONST DE_INVALIDFILES = &H7C
  38. CONST DE_DESTSAMETREE = &H7D
  39. CONST DE_FLDDESTISFILE = &H7E
  40. CONST DE_FILEDESTISFLD = &H80
  41. CONST DE_FILENAMETOOLONG = &H81
  42. CONST DE_DEST_IS_CDROM = &H82
  43. CONST DE_DEST_IS_DVD = &H83
  44. CONST DE_DEST_IS_CDRECORD = &H84
  45. CONST DE_FILE_TOO_LARGE = &H85
  46. CONST DE_SRC_IS_CDROM = &H86
  47. CONST DE_SRC_IS_DVD = &H87
  48. CONST DE_SRC_IS_CDRECORD = &H88
  49. CONST DE_ERROR_MAX = &HB7
  50. CONST UNKNOWN = &H402
  51. CONST ERRORONDEST = &H10000
  52. CONST DE_ROOTDIR_ERRORONDEST = &H10074
  53.  
  54. TYPE SHFILEOPSTRUCTA
  55.     hwnd AS _OFFSET
  56.     $IF 64BIT THEN
  57.         wfunc AS _UNSIGNED _INTEGER64 'To - From, From - To Flags
  58.     $ELSE
  59.     wfunc AS _UNSIGNED LONG
  60.     $END IF
  61.     pFrom AS _OFFSET
  62.     pTo AS _OFFSET
  63.     fFlags AS LONG
  64.     fAnyOperationsAborted AS _BYTE
  65.     hNameMappings AS _OFFSET
  66.     lpszProgressTitle AS _OFFSET
  67.  
  68. TYPE SHQUERYRBINFO
  69.     $IF 64BIT THEN
  70.         cbsize AS _INTEGER64
  71.         i64Size AS _INTEGER64
  72.         i64NumItems AS _INTEGER64
  73.     $ELSE
  74.     cbsize AS LONG
  75.     i64Size AS _INTEGER64
  76.     i64NumItems AS _INTEGER64
  77.     $END IF
  78.  
  79.     FUNCTION FileOperation% ALIAS SHFileOperationA (lpFileOp AS SHFILEOPSTRUCTA)
  80.     FUNCTION EmptyRecycleBin% ALIAS SHEmptyRecycleBinA (BYVAL hwnd AS LONG, BYVAL pszRootPath AS _OFFSET, BYVAL dwFlags AS LONG)
  81.     FUNCTION QueryRecycleBin~& ALIAS SHQueryRecycleBinA (pszRootPath AS STRING, pSHQueryRBInfo AS SHQUERYRBINFO)
  82.  
  83. 'Test code
  84. 'IF _FILEEXISTS(_DIR$("desktop") + "this is a test.txt") = 0 THEN
  85. '    OPEN _DIR$("desktop") + "this is a test.txt" FOR OUTPUT AS #1
  86. '    CLOSE #1
  87. 'END IF
  88. 'PRINT Copy(_DIR$("desktop") + "this is a test.txt", _DIR$("desktop") + "this is a test as well.txt")
  89. '_DELAY 2
  90. 'PRINT Rename(_DIR$("desktop") + "this is a test as well.txt", _DIR$("desktop") + "this is a test also.txt")
  91. '_DELAY 2
  92. 'PRINT Recycle(_DIR$("desktop") + "this is a test also.txt")
  93. '_DELAY 2
  94. 'PRINT GetRecycleInfo
  95. '_DELAY 2
  96. 'PRINT EmptyBin
  97. 'SLEEP
  98.  
  99. 'DIM cart(5) AS STRING
  100. 'cart(1) = _DIR$("desktop") + "QB64 x64\GetComputerName.bas"
  101. 'cart(2) = _DIR$("desktop") + "QB64 x64\timediff.bas"
  102. 'cart(3) = _DIR$("desktop") + "QB64 x64\qrtag api.bas"
  103. 'cart(4) = _DIR$("desktop") + "QB64 x64\Genderize API.bas"
  104. 'cart(5) = _DIR$("desktop") + "QB64 x64\rewind.png.MEM"
  105.  
  106. 'DIM dest AS STRING
  107. 'dest = _DIR$("desktop")
  108.  
  109. 'a = RunTransaction(cart(), dest, 2)
  110.  
  111. 'bplus backup test code
  112. SHELL _HIDE "PowerShell Get-ChildItem '" + _STARTDIR$ + "' -exclude *.exe | where {! $_.PSIsContainer} | foreach {$_.Name} | Out-File dirslist.txt -Encoding ASCII" 'Replace _STARTDIR$ with whatever directory contains the files
  113. '                                                                                                                                                                    used -exclude *.exe since you said you didn't want EXEs to be copied
  114. OPEN "dirslist.txt" FOR BINARY AS #1
  115.  
  116.     IF NOT EOF(1) THEN
  117.         x = x + 1
  118.         REDIM _PRESERVE filelist(x) AS STRING
  119.         LINE INPUT #1, filelist(x)
  120.         filelist(x) = _STARTDIR$ + "\" + filelist(x)
  121.     END IF
  122. dest = _DIR$("desktop") + "Test Folder"
  123. a = RunTransaction(filelist(), dest, 2)
  124.  
  125. FUNCTION GetRecycleInfo$
  126.     DIM RecycleInfo AS SHQUERYRBINFO
  127.     DIM path AS STRING
  128.     DIM a~&
  129.     path = "" + CHR$(0)
  130.     RecycleInfo.cbsize = LEN(RecycleInfo)
  131.     a~& = QueryRecycleBin(path, RecycleInfo)
  132.     GetRecycleInfo = _TRIM$(STR$(RecycleInfo.i64Size)) + " bytes, " + _TRIM$(STR$(RecycleInfo.i64NumItems)) + " items"
  133.  
  134. FUNCTION Recycle% (file AS STRING)
  135.     DIM lpFileOp AS SHFILEOPSTRUCTA
  136.     DIM doublenull AS STRING
  137.     doublenull = CHR$(0) + CHR$(0)
  138.     file = file + doublenull
  139.     lpFileOp.hwnd = _WINDOWHANDLE
  140.     lpFileOp.wfunc = FO_DELETE
  141.     lpFileOp.pFrom = _OFFSET(file)
  142.     lpFileOp.fFlags = FOF_ALLOWUNDO + FOF_WANTNUKEWARNING
  143.     Recycle = FileOperation(lpFileOp)
  144.  
  145. FUNCTION Copy% (file AS STRING, dest AS STRING)
  146.     DIM lpFileOp AS SHFILEOPSTRUCTA
  147.     DIM doublenull AS STRING
  148.     doublenull = CHR$(0) + CHR$(0)
  149.     file = file + doublenull
  150.     dest = dest + doublenull
  151.     lpFileOp.hwnd = _WINDOWHANDLE
  152.     lpFileOp.wfunc = FO_COPY
  153.     lpFileOp.pFrom = _OFFSET(file)
  154.     lpFileOp.pTo = _OFFSET(dest)
  155.     lpFileOp.fFlags = FOF_ALLOWUNDO
  156.     Copy = FileOperation(lpFileOp)
  157.  
  158. FUNCTION Move% (file AS STRING, dest AS STRING)
  159.     DIM lpFileOp AS SHFILEOPSTRUCTA
  160.     DIM doublenull AS STRING
  161.     doublenull = CHR$(0) + CHR$(0)
  162.     file = file + doublenull
  163.     dest = dest + doublenull
  164.     lpFileOp.hwnd = _WINDOWHANDLE
  165.     lpFileOp.wfunc = FO_MOVE
  166.     lpFileOp.pFrom = _OFFSET(file)
  167.     lpFileOp.pTo = _OFFSET(dest)
  168.     lpFileOp.fFlags = FOF_ALLOWUNDO
  169.     Move = FileOperation(lpFileOp)
  170.  
  171. FUNCTION Rename% (file AS STRING, newname AS STRING)
  172.     DIM lpFileOp AS SHFILEOPSTRUCTA
  173.     DIM doublenull AS STRING
  174.     doublenull = CHR$(0) + CHR$(0)
  175.     file = file + doublenull
  176.     newname = newname + doublenull
  177.     lpFileOp.hwnd = _WINDOWHANDLE
  178.     lpFileOp.wfunc = FO_RENAME
  179.     lpFileOp.pFrom = _OFFSET(file)
  180.     lpFileOp.pTo = _OFFSET(newname)
  181.     lpFileOp.fFlags = FOF_ALLOWUNDO
  182.     Rename = FileOperation(lpFileOp)
  183.  
  184. FUNCTION EmptyBin%
  185.     DIM drive AS STRING
  186.     drive = ""
  187.     EmptyBin = EmptyRecycleBin(0, _OFFSET(drive), 0)
  188.  
  189. FUNCTION RunTransaction (filecart() AS STRING, dest AS STRING, mode AS INTEGER) 'dest is optional, only used for Copy and Move
  190.     DIM x AS INTEGER
  191.     DIM a AS INTEGER
  192.     IF RIGHT$(dest, 1) <> "\" THEN
  193.         dest = dest + "\"
  194.     END IF
  195.     SELECT CASE mode
  196.         CASE 1 'Recycle
  197.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  198.                 IF filecart(x) <> "" THEN
  199.                     a = Recycle(filecart(x))
  200.                     PRINT "Recycling item "; x; " of "; UBOUND(filecart); " ("; filecart(x); ")"
  201.                 END IF
  202.             NEXT
  203.         CASE 2 'Copy
  204.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  205.                 IF filecart(x) <> "" THEN
  206.                     a = Copy(filecart(x), dest + StripDirectory(filecart(x)))
  207.                     PRINT "Copying item "; x; " of "; UBOUND(filecart); " ("; filecart(x); ")"
  208.                 END IF
  209.             NEXT
  210.         CASE 3 'Move
  211.             FOR x = LBOUND(filecart) TO UBOUND(filecart)
  212.                 IF filecart(x) <> "" THEN
  213.                     a = Move(filecart(x), dest + StripDirectory(filecart(x)))
  214.                     PRINT "Moving item "; x; " of "; UBOUND(filecart); " ("; filecart(x); ")"
  215.                 END IF
  216.             NEXT
  217.     END SELECT
  218.  
  219. FUNCTION StripDirectory$ (OFile$)
  220.     DO
  221.         OFile$ = RIGHT$(OFile$, LEN(OFile$) - INSTR(OFile$, "\"))
  222.     LOOP WHILE INSTR(OFile$, "\")
  223.     StripDirectory$ = OFile$
« Last Edit: September 24, 2020, 01:05:42 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Need ideas for more API usage....
« Reply #6 on: September 24, 2020, 01:11:45 am »
I would like to write a QB64 program, compile it and run it in shell from same program that wrote the program.
I don't know if API can help with that? What do you think?

I suppose you could do this by making a console program, having it write a BAS source for a console program using PRINT commands,  then SHELLing to QB64 to compile the program then SHELL the program inside the first console program which will run the new one in the same window.
Shuwatch!