DreamDancer

Trello Json Decoder

Jul 15th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' fair warning, this was written in power basic, and sort of just slapped together on the fly
  2.  
  3. #PBFORMS CREATED V1.51
  4. '------------------------------------------------------------------------------
  5. ' The first line in this file is a PB/Forms metastatement.
  6. ' It should ALWAYS be the first line of the file. Other
  7. ' PB/Forms metastatements are placed at the beginning and
  8. ' end of "Named Blocks" of code that should be edited
  9. ' with PBForms only. Do not manually edit or delete these
  10. ' metastatements or PB/Forms will not be able to reread
  11. ' the file correctly.  See the PB/Forms documentation for
  12. ' more information.
  13. ' Named blocks begin like this:    #PBFORMS BEGIN ...
  14. ' Named blocks end like this:      #PBFORMS END ...
  15. ' Other PB/Forms metastatements such as:
  16. '     #PBFORMS DECLARATIONS
  17. ' are used by PB/Forms to insert additional code.
  18. ' Feel free to make changes anywhere else in the file.
  19. '------------------------------------------------------------------------------
  20.  
  21. #COMPILE EXE
  22. #DIM ALL
  23.  
  24. '------------------------------------------------------------------------------
  25. '   ** Includes **
  26. '------------------------------------------------------------------------------
  27. #PBFORMS BEGIN INCLUDES
  28. %USEMACROS = 1
  29. #IF NOT %DEF(%WINAPI)
  30.     #INCLUDE "WIN32API.INC"
  31. #ENDIF
  32. #IF NOT %DEF(%COMMCTRL_INC)
  33.     #INCLUDE "COMMCTRL.INC"
  34. #ENDIF
  35. #INCLUDE "PBForms.INC"
  36. #PBFORMS END INCLUDES
  37. '------------------------------------------------------------------------------
  38.  
  39. '------------------------------------------------------------------------------
  40. '   ** Constants **
  41. '------------------------------------------------------------------------------
  42. #PBFORMS BEGIN CONSTANTS
  43. %IDD_CONVERTJSON        =  101
  44. %IDR_ACCELERATOR1       =  102
  45. %IDR_MENU1              =  103
  46.  
  47. %IDSB_STATUS            = 1201
  48. %IDLB_CARDS             = 1202
  49.  
  50. %IDM_FILE_CONVERTJSON   = 1001
  51. %IDM_FILE_RECENTACTS    = 1002
  52. %IDM_FILE_CARDLIST      = 1004
  53. %IDM_FILE_CUSTOM        = 1005
  54. %IDM_FILE_ANALYZE       = 1006
  55. %IDM_FILE_EXIT          = 1007
  56.  
  57. %IDBT_CANCEL            = 5001
  58. %IDBT_GENERATELIST      = 5002
  59. %IDOPT_LISTORDER1       = 5010
  60. %IDOPT_LISTORDER2       = 5011
  61. %IDCK_LISTS             = 6000
  62. %IDCK_LABELS            = 7000
  63.  
  64. #PBFORMS END CONSTANTS
  65. '------------------------------------------------------------------------------
  66.  
  67. '------------------------------------------------------------------------------
  68. '   ** Declarations **
  69. '------------------------------------------------------------------------------
  70. UNION QUADTODOUBLE
  71.     iParts  AS FILETIME
  72.     iQuad   AS QUAD
  73. END UNION
  74.  
  75. %UNIXTOWINTIME  = 11644473600   ' 11,644,473,600
  76. %UNIXMULTIPLY   = 10000000      '
  77.  
  78. GLOBAL hCustom      AS DWORD
  79.  
  80. '------------------------------------------------------------------------------
  81.  
  82. '------------------------------------------------------------------------------
  83. '   ** Main Application Entry Point **
  84. '------------------------------------------------------------------------------
  85. FUNCTION PBMAIN()
  86.     PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
  87.         %ICC_INTERNET_CLASSES)
  88.  
  89. LOCAL Work AS STRING, uQuad AS QUAD
  90.     uQuad = GetUtcOffset(0)
  91.     Work = FORMAT$(uQuad, "0,0")
  92.     #DEBUG PRINT Work
  93.  
  94.     ShowConverJson %HWND_DESKTOP
  95. END FUNCTION
  96. '------------------------------------------------------------------------------
  97.  
  98. '------------------------------------------------------------------------------
  99. '   ** CallBacks **
  100. '------------------------------------------------------------------------------
  101. CALLBACK FUNCTION ShowConverJsonProc()
  102. STATIC FileName, FileFilter AS STRING
  103. LOCAL Work                  AS STRING
  104. LOCAL FileInfo              AS DIRDATA
  105. LOCAL FileDate              AS FILETIME
  106. LOCAL SysTime               AS SYSTEMTIME
  107. LOCAL jFile, tFile          AS QUAD
  108.  
  109.     SELECT CASE AS LONG CB.MSG
  110.         CASE %WM_INITDIALOG
  111.             ' Initialization handler
  112.  
  113.         CASE %WM_SIZE
  114.             ' Dialog has been resized
  115.            LOCAL DX, DY, SX, SY    AS LONG
  116.             CONTROL SEND CB.HNDL, %IDSB_STATUS, CB.MSG, CB.WPARAM, CB.LPARAM
  117.             DIALOG GET CLIENT CB.HNDL TO DX, DY
  118.             CONTROL GET SIZE CB.HNDL, %IDSB_STATUS TO SX, SY
  119.             DY = DY - SY
  120.             CONTROL SET LOC CB.HNDL, %IDLB_CARDS, 0, 0
  121.             CONTROL SET SIZE CB.HNDL, %IDLB_CARDS, DX, DY
  122.  
  123.         CASE %WM_NCACTIVATE
  124.             STATIC hWndSaveFocus AS DWORD
  125.             IF ISFALSE CB.WPARAM THEN
  126.                 ' Save control focus
  127.                hWndSaveFocus = GetFocus()
  128.             ELSEIF hWndSaveFocus THEN
  129.                 ' Restore control focus
  130.                SetFocus(hWndSaveFocus)
  131.                 hWndSaveFocus = 0
  132.             END IF
  133.  
  134.         CASE %WM_COMMAND
  135.             ' Process control notifications
  136.            SELECT CASE AS LONG CB.CTL
  137.  
  138.                 CASE %IDM_FILE_CONVERTJSON, %IDM_FILE_RECENTACTS, %IDM_FILE_CARDLIST, %IDM_FILE_CUSTOM
  139.                     FileFilter = CHR$("JSON Files", 0, "*.json", 0)
  140.                     DISPLAY OPENFILE CB.HNDL, , , "Select JSON File", EXE.PATH$, _
  141.                     FileFilter, "", "", _
  142.                     %OFN_ENABLESIZING OR %OFN_FILEMUSTEXIST _
  143.                     TO FileName
  144.  
  145.                     IF (LEN(FileName) > 0) THEN
  146.                         Work = DIR$(FileName, TO FileInfo)
  147.                         jFile = FileInfo.LastWriteTime
  148.                         DIR$ CLOSE
  149.                         REPLACE ".json" WITH ".txt" IN Work
  150.                         Work = DIR$(Work, TO FileInfo)
  151.                         IF (LEN(Work) = 0) THEN
  152.                             tFile = jFile
  153.                         ELSE
  154.                             tFile = FileInfo.LastWriteTime
  155.                         END IF
  156.                         DIR$ CLOSE
  157.                         IF (tFile <= jFile) THEN
  158.                             ConvertJson CB.HNDL, FileName
  159.                             SplitJson CB.HNDL, FileName
  160.                         END IF
  161.                         SELECT CASE AS LONG CB.CTL
  162.                             CASE %IDM_FILE_CONVERTJSON
  163.                                 CreateCards CB.HNDL, FileName, "actions.mbox", %TRUE
  164.                                 CreateCards CB.HNDL, FileName, "cards.mbox", %FALSE
  165.                         END SELECT
  166.                         SELECT CASE AS LONG CB.CTL
  167.                             CASE %IDM_FILE_CONVERTJSON, %IDM_FILE_RECENTACTs
  168.                                 ExtractRecentActions CB.HNDL, FileName
  169.                             CASE %IDM_FILE_CARDLIST
  170.                                 CreateCardList CB.HNDL, FileName
  171.                             CASE %IDM_FILE_CUSTOM
  172.                                 hCustom = ShowCustomDialog(CB.HNDL, FileName)
  173.                                 DIALOG SHOW MODELESS hCustom, CALL ShowConverJsonProc
  174.                         END SELECT
  175.                         LISTBOX ADD CB.HNDL, %IDLB_CARDS, "Done"
  176.                     END IF
  177.  
  178.                 CASE %IDM_FILE_ANALYZE
  179.                     FileFilter = CHR$("JSON Files", 0, "*.json", 0)
  180.                     DISPLAY OPENFILE CB.HNDL, , , "Select JSON File", EXE.PATH$, _
  181.                     FileFilter, "", "", _
  182.                     %OFN_ENABLESIZING OR %OFN_FILEMUSTEXIST _
  183.                     TO FileName
  184.  
  185.                     IF (LEN(FileName) > 0) THEN
  186.                         Work = DIR$(FileName, TO FileInfo)
  187.                         jFile = FileInfo.LastWriteTime
  188.                         DIR$ CLOSE
  189.                         REPLACE ".json" WITH ".txt" IN Work
  190.                         Work = DIR$(Work, TO FileInfo)
  191.                         IF (LEN(Work) = 0) THEN
  192.                             tFile = jFile
  193.                         ELSE
  194.                             tFile = FileInfo.LastWriteTime
  195.                         END IF
  196.                         DIR$ CLOSE
  197.                         IF (tFile < jFile) THEN
  198.                             ConvertJson CB.HNDL, FileName
  199.                             SplitJson CB.HNDL, FileName
  200.                         END IF
  201.                         AnalyzeActions CB.HNDL, FileName
  202.                         LISTBOX ADD CB.HNDL, %IDLB_CARDS, "Done"
  203.                     END IF
  204.  
  205.                 CASE %IDBT_CANCEL ' can only come from the child dialog
  206.                    IF (hCustom <> 0) THEN
  207.                         DIALOG END hCustom
  208.                         hCustom = 0
  209.                     END IF
  210.  
  211.                 CASE %IDBT_GENERATELIST
  212.                     CreateCardList CB.HNDL, FileName
  213.                     LISTBOX ADD CB.HNDL, %IDLB_CARDS, "Done"
  214.  
  215.                 CASE %IDM_FILE_EXIT
  216.                     DIALOG END CB.HNDL
  217.  
  218.             END SELECT
  219.     END SELECT
  220. END FUNCTION
  221. '------------------------------------------------------------------------------
  222.  
  223.  
  224. '------------------------------------------------------------------------------
  225. '   ** Dialogs **
  226. '------------------------------------------------------------------------------
  227. FUNCTION ShowConverJson(BYVAL hParent AS DWORD) AS LONG
  228.     LOCAL lRslt AS LONG
  229.  
  230. #PBFORMS BEGIN DIALOG %IDD_CONVERTJSON->%IDR_MENU1->%IDR_ACCELERATOR1
  231.     LOCAL hDlg  AS DWORD
  232.  
  233.     DIALOG NEW PIXELS, hParent, "Convert Json", 598, 310, 376, 343, %WS_POPUP _
  234.         OR %WS_BORDER OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
  235.         %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
  236.         %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
  237.         %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
  238.         OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
  239.     CONTROL ADD STATUSBAR, hDlg, %IDSB_STATUS, "Status", 0, 306, _
  240.         376, 19, %WS_CHILD OR %WS_VISIBLE, %WS_EX_TRANSPARENT OR %WS_EX_LEFT _
  241.         OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
  242.     CONTROL ADD LISTBOX, hDlg, %IDLB_CARDS, , 38, 89, 277, 147, %WS_CHILD OR _
  243.         %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL, %WS_EX_CLIENTEDGE OR _
  244.         %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
  245.  
  246.     AttachMENU1 hDlg
  247.  
  248.     AttachACCELERATOR1 hDlg
  249. #PBFORMS END DIALOG
  250.  
  251.     DIALOG SHOW MODAL hDlg, CALL ShowConverJsonProc TO lRslt
  252.  
  253. #PBFORMS BEGIN CLEANUP %IDD_CONVERTJSON
  254. #PBFORMS END CLEANUP
  255.  
  256.     FUNCTION = lRslt
  257. END FUNCTION
  258. '------------------------------------------------------------------------------
  259.  
  260. '------------------------------------------------------------------------------
  261. FUNCTION ShowCustomDialog(hParent AS DWORD, JsonFile AS STRING) AS DWORD
  262. LOCAL hChild                AS DWORD
  263. LOCAL Lists(), Labels()     AS STRING
  264. LOCAL DataBlock()           AS STRING
  265. LOCAL SectionPath, Work     AS STRING
  266. LOCAL FileIn, DataIndex     AS LONG
  267. LOCAL CiDx                  AS LONG
  268. LOCAL Caption, SizeY        AS LONG
  269.  
  270.     DataIndex = 0
  271.     REDIM DataBlock(0)
  272.     FetchDataSet hParent, JsonFile, "\lists.mbox", DataBlock()
  273.     FOR CiDx = 0 TO UBOUND(DataBlock)
  274.         Work = Simple(ExtractItemValue("name", DataBlock(CiDx)))
  275.         IF (LEN(Work) > 0) THEN
  276.             REDIM PRESERVE Lists(DataIndex)
  277.             Lists(DataIndex) = Work
  278.             INCR DataIndex
  279.         END IF
  280.     NEXT CiDx
  281.  
  282.     SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
  283.     FileIn = FREEFILE
  284.     OPEN SectionPath &"\globals.mbox" FOR INPUT AS FileIn
  285.     LINE INPUT #FileIn, Work
  286.  
  287.     DataIndex = 0
  288.     REDIM Labels(DataIndex)
  289.  
  290.     ' find "labelNames" in globals
  291.    DO
  292.         LINE INPUT #FileIn, Work
  293.         IF (INSTR(Work, "labelNames") > 0) THEN EXIT DO
  294.     LOOP
  295.     LINE INPUT #FileIn, Work
  296.     DO
  297.         LINE INPUT #FileIn, Work
  298.         IF (VAL(Work) = 2) THEN EXIT DO
  299.         REDIM PRESERVE Labels(DataIndex)
  300.         Labels(DataIndex) = PARSE$(Work, ":", 2)
  301.         REPLACE "," WITH "" IN Labels(DataIndex)
  302.         REPLACE CHR$(34) WITH "" IN Labels(DataIndex)
  303.         INCR DataIndex
  304.     LOOP
  305.     CLOSE FileIn
  306.  
  307.     Caption = GetSystemMetrics(%SM_CYCAPTION) + (GetSystemMetrics(%SM_CYFIXEDFRAME) * 2)
  308.     SizeY = Caption + (UBOUND(Labels) * 16) + (UBOUND(Lists) * 16) + 112
  309.  
  310.     DIALOG NEW PIXELS, hParent, "Custom Lists", , , 256, SizeY, %WS_POPUP _
  311.         OR %WS_BORDER OR %WS_CAPTION OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN _
  312.         OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE _
  313.         OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
  314.         %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hChild
  315.     CONTROL ADD BUTTON, hChild, %IDBT_GENERATELIST, "Generate List", 0, 0, 120, 24
  316.     CONTROL ADD BUTTON, hChild, %IDBT_CANCEL, "Cancel", 136, 0, 120, 24
  317.     CONTROL ADD OPTION, hChild, %IDOPT_LISTORDER1, "Find In Lists First", 10, 26, 120, 16
  318.     CONTROL ADD OPTION, hChild, %IDOPT_LISTORDER2, "Find In Labels First", 10, 42, 120, 16
  319.     CONTROL SET OPTION  hChild, %IDOPT_LISTORDER1, %IDOPT_LISTORDER1, %IDOPT_LISTORDER2
  320.  
  321.     CONTROL ADD LABEL, hChild, 0, "Select List (none = all)", 10, 60, 240, 16
  322.  
  323.     CiDx = 78
  324.     FOR DataIndex = 0 TO UBOUND(Lists)
  325.         CONTROL ADD CHECKBOX, hChild, %IDCK_LISTS + DataIndex, Lists(DataIndex), 10, _
  326.             (CiDx + (DataIndex * 16)), 240, 16
  327.     NEXT DataIndex
  328.     DIALOG SET USER hChild, 1, UBOUND(Lists)
  329.  
  330.     CiDx = (CiDx + (DataIndex * 16)) + 4
  331.     CONTROL ADD LABEL, hChild, 0, "Select Labels (none = all)", 10, CiDx, 240, 16
  332.  
  333.     CiDx = CiDx + 16
  334.     FOR DataIndex = 0 TO UBOUND(Labels)
  335.         CONTROL ADD CHECKBOX, hChild, %IDCK_LABELS + DataIndex, Labels(DataIndex), 10, _
  336.             (CiDx + (DataIndex * 16)), 240, 16
  337.     NEXT DataIndex
  338.     DIALOG SET USER hChild, 2, UBOUND(Labels)
  339.  
  340.     ShowCustomDialog = hChild
  341.  
  342. END FUNCTION
  343. '------------------------------------------------------------------------------
  344.  
  345. '------------------------------------------------------------------------------
  346. '   ** Menus **
  347. '------------------------------------------------------------------------------
  348. FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
  349. #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_CONVERTJSON
  350.     LOCAL hMenu   AS DWORD
  351.     LOCAL hPopUp1 AS DWORD
  352.  
  353.     MENU NEW BAR TO hMenu
  354.     MENU NEW POPUP TO hPopUp1
  355.     MENU ADD POPUP, hMenu, "File", hPopUp1, %MF_ENABLED
  356.         MENU ADD STRING, hPopUp1, "Convert Json", %IDM_FILE_CONVERTJSON, %MF_ENABLED
  357.         MENU ADD STRING, hPopUp1, "Extract Recent", %IDM_FILE_RECENTACTS, %MF_ENABLED
  358.         MENU ADD STRING, hPopUp1, "Create Card List", %IDM_FILE_CARDLIST, %MF_ENABLED
  359.         MENU ADD STRING, hPopUp1, "Create Custom List", %IDM_FILE_CUSTOM, %MF_ENABLED
  360.         MENU ADD STRING, hPopUp1, "Analyze Actions", %IDM_FILE_ANALYZE, %MF_ENABLED
  361.         MENU ADD STRING, hPopUp1, "-", 0, 0
  362.         MENU ADD STRING, hPopUp1, "Exit" + $TAB + "Alt+F4", %IDM_FILE_EXIT, %MF_ENABLED
  363.  
  364.     MENU ATTACH hMenu, hDlg
  365. #PBFORMS END MENU
  366.     FUNCTION = hMenu
  367. END FUNCTION
  368. '------------------------------------------------------------------------------
  369.  
  370. '------------------------------------------------------------------------------
  371. '   ** Accelerators **
  372. '------------------------------------------------------------------------------
  373. #PBFORMS BEGIN ASSIGNACCEL
  374. FUNCTION ASSIGNACCEL(tAccel AS ACCELAPI, BYVAL wKey AS WORD, BYVAL wCmd AS _
  375.     WORD, BYVAL byFVirt AS BYTE) AS LONG
  376.     tAccel.fVirt = byFVirt
  377.     tAccel.key   = wKey
  378.     tAccel.cmd   = wCmd
  379. END FUNCTION
  380. #PBFORMS END ASSIGNACCEL
  381. '------------------------------------------------------------------------------
  382.  
  383. '------------------------------------------------------------------------------
  384. FUNCTION AttachACCELERATOR1(BYVAL hDlg AS DWORD) AS DWORD
  385. #PBFORMS BEGIN ACCEL %IDR_ACCELERATOR1->%IDD_CONVERTJSON
  386.     LOCAL hAccel   AS DWORD
  387.     LOCAL tAccel() AS ACCELAPI
  388.     DIM   tAccel(1 TO 1) AS ACCELAPI
  389.  
  390.     ASSIGNACCEL tAccel(1), %VK_F4, %IDM_FILE_EXIT, %FVIRTKEY OR %FALT OR %FNOINVERT
  391.  
  392.     ACCEL ATTACH hDlg, tAccel() TO hAccel
  393. #PBFORMS END ACCEL
  394.     FUNCTION = hAccel
  395. END FUNCTION
  396. '------------------------------------------------------------------------------
  397.  
  398.  
  399. SUB ConvertJson(hDlg AS LONG, JsonFile AS STRING)
  400. LOCAL Chunk, Buffer, Work, FileName, Char, StatusText   AS STRING
  401. LOCAL FileIn, FileOut, InQuote, Depth, CiDx, Level      AS LONG
  402.  
  403.  
  404.   FileName = JsonFile
  405.   FileIn = FREEFILE
  406.   OPEN FileName FOR BINARY AS FileIn
  407.   REPLACE ".json" WITH ".txt" IN FileName
  408.   FileOut = FREEFILE
  409.   OPEN FileName FOR OUTPUT AS FileOut
  410.   Level = 1
  411.   Buffer = ""
  412.   InQuote = %FALSE
  413.   CiDx = 1
  414.   StatusText = "Loading "& PATHNAME$(NAMEX, JsonFile)
  415.   LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  416.   DIALOG DOEVENTS
  417.  
  418.   DO
  419.     IF (CiDx > LEN(Buffer)) THEN
  420.       Depth = SEEK(FileIn)
  421.       IF (Depth > LOF(FileIn)) THEN EXIT DO
  422.       StatusText = "Converting Block "& FORMAT$(Depth) &" of "& FORMAT$(LOF(FileIn))
  423.       STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  424.       DIALOG DOEVENTS
  425.       ' If (Depth > 32000) Then Exit Do
  426.      Chunk = STRING$(4096, $TAB)
  427.       GET #FileIn, , Chunk
  428.       Buffer = Buffer & Chunk
  429.       REPLACE $TAB WITH "" IN Buffer
  430.       CiDx = 1
  431.     END IF
  432.     Char = MID$(Buffer, CiDx, 1)
  433.     MID$(Buffer, CiDx, 1) = $TAB
  434.     IF (Char <> $TAB) THEN
  435.       IF (InQuote) THEN
  436.         Work = Work & Char
  437.         IF (Char = "\") THEN
  438.           IF (CiDx = LEN(Buffer)) THEN
  439.             ' fetch one more
  440.            Chunk = " "
  441.             GET #FileIn, , Chunk
  442.             Buffer = Buffer & Chunk
  443.           END IF
  444.           Work = Work & MID$(Buffer, CiDx + 1, 1)
  445.           MID$(Buffer, CiDx + 1, 1) = $TAB
  446.           Char = $TAB
  447.         END IF
  448.         IF (Char = CHR$(34)) THEN
  449.           InQuote = %FALSE
  450.         END IF
  451.       ELSE
  452.         IF (Char = "{") THEN
  453.           IF (CiDx = LEN(Buffer)) THEN
  454.             ' fetch one more
  455.            Chunk = " "
  456.             GET #FileIn, , Chunk
  457.             Buffer = Buffer & Chunk
  458.           END IF
  459.           IF (MID$(Buffer, CiDx + 1, 1) = "}") THEN
  460.             Work = Work &"{}"
  461.             MID$(Buffer, CiDx + 1, 1) = $TAB
  462.           ELSE
  463.             IF (LEN(Work) > 0) THEN
  464.               DumpOutput FileOut, Level, Work
  465.               Work = ""
  466.             END IF
  467.             DumpOutput FileOut, Level, "{"
  468.             Level = Level + 1
  469.           END IF
  470.         ELSEIF (Char = "}") THEN
  471.           IF (CiDx = LEN(Buffer)) THEN
  472.             ' fetch one more
  473.            Chunk = " "
  474.             GET #FileIn, , Chunk
  475.             Buffer = Buffer & Chunk
  476.           END IF
  477.           IF (LEN(Work) > 0) THEN
  478.             DumpOutput FileOut, Level, Work
  479.             Work = ""
  480.           END IF
  481.           Level = Level - 1
  482.           IF (MID$(Buffer, CiDx + 1, 1) = ",") THEN
  483.             DumpOutput FileOut, Level, "},"
  484.             MID$(Buffer, CiDx + 1, 1) = $TAB
  485.           ELSE
  486.             DumpOutput FileOut, Level, "}"
  487.           END IF
  488.         ELSEIF (Char = ",") THEN
  489.           Work = Work & Char
  490.           IF (LEN(Work) > 0) THEN
  491.             DumpOutput FileOut, Level, Work
  492.             Work = ""
  493.           END IF
  494.         ELSE
  495.           Work = Work & Char
  496.           IF (Char = CHR$(34)) THEN
  497.             InQuote = %TRUE
  498.           END IF
  499.           IF (Char = "[") THEN
  500.             Level = Level + 1
  501.           END IF
  502.           IF (Char = "]") THEN
  503.             Level = Level - 1
  504.           END IF
  505.         END IF ' big chain
  506.      END IF ' InQuote
  507.    END IF ' Char <> $TAB
  508.    CiDx = CiDx + 1
  509.   LOOP
  510.   CLOSE
  511.   STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  512. END SUB
  513.  
  514.  
  515. SUB DumpOutput(FileOut AS LONG, Level AS LONG, Work AS STRING)
  516.     ' this is easier to do than over testing in the above subroutine
  517.    IF (RIGHT$(Work, 1) = "[") THEN
  518.         PRINT #FileOut, FORMAT$(Level - 1) & STRING$((Level - 1) * 2, 32) & Work
  519.     ELSE
  520.         PRINT #FileOut, FORMAT$(Level) & STRING$(Level * 2, 32) & Work
  521.     END IF
  522. END SUB
  523.  
  524.  
  525. SUB SplitJson(hDlg AS LONG, JsonFile AS STRING)
  526. LOCAL FileIn, FileOut, Depth    AS LONG
  527. LOCAL LineCount                 AS LONG
  528. LOCAL Work, FileName            AS STRING
  529. LOCAL SectionPath, SectionName  AS STRING
  530. LOCAL StatusText                AS STRING
  531. LOCAL Exported                  AS LONG ' boolean value
  532.  
  533.     SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
  534.     IF (ISTRUE ISFOLDER(SectionPath)) THEN
  535.         IF (DIR$(SectionPath &"\*.mbox") <> "") THEN
  536.             KILL SectionPath &"\*.mbox"
  537.         END IF
  538.         DIR$ CLOSE
  539.     ELSE
  540.         MKDIR SectionPath
  541.     END IF
  542.  
  543.     FileIn = FREEFILE
  544.     FileName = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile) &".txt"
  545.     OPEN FileName FOR INPUT AS FileIn
  546.     ' global text comes first, dispose of first line and open global
  547.    LINE INPUT #FileIn, Work
  548.     FileOut = FREEFILE
  549.     OPEN SectionPath &"\globals.mbox" FOR APPEND AS FileOut
  550.     SectionName = "globals"
  551.     LineCount = 0
  552.     StatusText = "Converting "& PATHNAME$(NAMEX, JsonFile)
  553.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  554.     DIALOG DOEVENTS
  555.  
  556.     DO
  557.         LINE INPUT #FileIn, Work
  558.         Depth = VAL(Work)
  559.         IF (Depth = 1) THEN EXIT DO
  560.         IF (Depth = 3) THEN
  561.             INCR LineCount
  562.             StatusText = "Extracting "& SectionName &" "& FORMAT$(LineCount)
  563.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  564.             DIALOG DOEVENTS
  565.         END IF
  566.         Exported = %FALSE
  567.         IF ((Depth = 2) AND (INSTR(Work, "[") > 0)) THEN
  568.             ' new section, close current, open new based on section name
  569.            CLOSE FileOut
  570.             SectionName = PARSE$(TRIM$(MID$(Work, 2)), ":", 1)
  571.             REPLACE CHR$(34) WITH "" IN SectionName
  572.             FileOut = FREEFILE
  573.             OPEN SectionPath &"\"& SectionName &".mbox" FOR APPEND AS FileOut
  574.             PRINT #FileOut, Work
  575.             Exported = %TRUE
  576.             LineCount = 0
  577.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, SectionName
  578.             DIALOG DOEVENTS
  579.         END IF
  580.         IF ((Depth = 2) AND (INSTR(Work, "]") > 0)) THEN
  581.             ' close current and reopen global
  582.            IF (ISFALSE Exported) THEN
  583.                 PRINT #FileOut, Work
  584.             END IF
  585.             CLOSE FileOut
  586.             FileOut = FREEFILE
  587.             OPEN SectionPath &"\globals.mbox" FOR APPEND AS FileOut
  588.             Exported = %TRUE
  589.         END IF
  590.         IF (ISFALSE Exported) THEN
  591.             PRINT #FileOut, Work
  592.         END IF
  593.     LOOP
  594.  
  595.     CLOSE FileIn
  596.     CLOSE FileOut
  597.     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  598.  
  599. END SUB
  600.  
  601.  
  602. SUB CreateCards(hDlg AS LONG, JsonFile AS STRING, SectionName AS STRING, kJson AS LONG)
  603. LOCAL FileIn, FileOut, Depth    AS LONG
  604. LOCAL LineCount, wIndex         AS LONG
  605. LOCAL idShort                   AS LONG
  606. LOCAL Work, FileName            AS STRING
  607. LOCAL rFix, nFix                AS STRING
  608. LOCAL SectionPath, CardName     AS STRING
  609. LOCAL Char, Opener, Prefix      AS STRING
  610. LOCAL StatusText, Card          AS STRING
  611. LOCAL Exported                  AS LONG ' boolean value
  612.  
  613.     SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
  614.     IF (ISTRUE kJson) THEN
  615.         IF (DIR$(SectionPath &"\*.json") <> "") THEN
  616.             KILL SectionPath &"\*.json"
  617.         END IF
  618.         DIR$ CLOSE
  619.     END IF
  620.  
  621.     FileIn = FREEFILE
  622.     OPEN SectionPath &"\"& SectionName FOR INPUT AS FileIn
  623.     ' dispose of first item, do until depth=2
  624.    LINE INPUT #FileIn, Work
  625.     StatusText = "Creating Cards"
  626.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  627.     DIALOG DOEVENTS
  628.  
  629.     DO
  630.         LINE INPUT #FileIn, Work
  631.         Depth = VAL(Work)
  632.         IF (Depth = 2) THEN EXIT DO
  633.         Work = TRIM$(MID$(Work, 2))
  634.         REPLACE CHR$(34) WITH "|" IN Work
  635.         nFix = PARSE$(Work, "|", 2)
  636.         REPLACE "|"& nFix WITH "|"& Prefix & nFix IN Work
  637.         Char = RIGHT$(Work, 1)
  638.         IF ((Char = ":") OR (Char = "[")) THEN
  639.             Prefix = Prefix & nFix &"."
  640.             Opener = Opener & Char
  641.         END IF
  642.         Char = LEFT$(Work, 1)
  643.         IF ((Char = "]") AND (RIGHT$(Opener, 1) = "[") AND (Depth > 3)) THEN
  644.             IF (LEN(Prefix) > 0) THEN
  645.                 wIndex = PARSECOUNT(Prefix, ".")
  646.                 Char = PARSE$(Prefix, ".", wIndex - 1) &"."
  647.                 REPLACE Char WITH "" IN Prefix
  648.                 Opener = LEFT$(Opener, LEN(Opener) - 1)
  649.             END IF
  650.         END IF
  651.         IF ((Char = "}") AND (RIGHT$(Opener, 1) = ":") AND (Depth > 3)) THEN
  652.             IF (LEN(Prefix) > 0) THEN
  653.                 wIndex = PARSECOUNT(Prefix, ".")
  654.                 Char = PARSE$(Prefix, ".", wIndex - 1) &"."
  655.                 REPLACE Char WITH "" IN Prefix
  656.                 Opener = LEFT$(Opener, LEN(Opener) - 1)
  657.             END IF
  658.         END IF
  659.         Card = Card & $TAB & FORMAT$(Depth) & Work
  660.         IF ((Depth = 3) AND (INSTR(Work, "}") > 0)) THEN
  661.             ' we are only interested in closing brackets
  662.            IF (ISTRUE kJson) THEN
  663.                 idShort = VAL(ExtractItemValue("data.card.idShort", Card))
  664.             ELSE
  665.                 idShort = VAL(ExtractItemValue("idShort", Card))
  666.             END IF
  667.             StatusText = "Updating Card "& FORMAT$(idShort)
  668.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  669.             DIALOG DOEVENTS
  670.             FileName = SectionPath &"\card-"& FORMAT$(idShort, "000") &".json"
  671.             FileOut = FREEFILE
  672.             OPEN FileName FOR APPEND AS FileOut
  673.             FOR wIndex = 3 TO 9
  674.                 REPLACE ($TAB & FORMAT$(wIndex)) WITH ($CRLF & STRING$(wIndex, $TAB)) IN Card
  675.             NEXT wIndex
  676.             PRINT #FileOut, Card
  677.             CLOSE FileOut
  678.             Card = ""
  679.         END IF
  680.     LOOP
  681.     CLOSE FileIn
  682.     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  683.  
  684. END SUB
  685.  
  686.  
  687. FUNCTION ExtractItemValue(Hunter AS STRING, CardItem AS STRING) AS STRING
  688. LOCAL TiDx      AS LONG
  689. LOCAL Results   AS STRING
  690.  
  691.     Results = CardItem
  692.     TiDx = INSTR(Results, "|"& Hunter &"|")
  693.     IF (TiDx = 0) THEN
  694.         ExtractItemValue = ""
  695.         EXIT FUNCTION
  696.     END IF
  697.  
  698.     Results = MID$(Results, TiDx)
  699.     Results = PARSE$(Results, $TAB, 1)
  700.     TiDx = INSTR(Results, ":")
  701.     Results = MID$(Results, TiDx + 1)
  702.  
  703.     IF (RIGHT$(Results, 1) = ",") THEN
  704.         Results = LEFT$(Results, LEN(Results) - 1)
  705.     END IF
  706.  
  707.     ExtractItemValue = Results
  708. END FUNCTION
  709.  
  710.  
  711. FUNCTION ExtractDataBlock(Hunter AS STRING, CardItem AS STRING) AS STRING
  712. LOCAL TiDx      AS LONG
  713. LOCAL Results   AS STRING
  714.  
  715.     Results = CardItem
  716.     TiDx = INSTR(Results, "|"& Hunter &"|")
  717.     IF (TiDx = 0) THEN
  718.         ExtractDataBlock = ""
  719.         EXIT FUNCTION
  720.     END IF
  721.     Results = MID$(Results, TiDx)
  722.     TiDx = INSTR(Results, "]")
  723.     IF (TiDx = 0) THEN
  724.         ExtractDataBlock = ""
  725.         EXIT FUNCTION
  726.     END IF
  727.     Results = LEFT$(Results, TiDx)
  728.     ExtractDataBlock = Results
  729. END FUNCTION
  730.  
  731. FUNCTION ExtractSubDataBlock(Hunter AS STRING, CardItem AS STRING) AS STRING
  732. LOCAL TiDx      AS LONG
  733. LOCAL Results   AS STRING
  734.  
  735.     Results = CardItem
  736.     TiDx = INSTR(Results, "|"& Hunter &"|")
  737.     IF (TiDx = 0) THEN
  738.         ExtractSubDataBlock = ""
  739.         EXIT FUNCTION
  740.     END IF
  741.     Results = MID$(Results, TiDx)
  742.     TiDx = INSTR(Results, "}")
  743.     IF (TiDx = 0) THEN
  744.         ExtractSubDataBlock = ""
  745.         EXIT FUNCTION
  746.     END IF
  747.     Results = LEFT$(Results, TiDx)
  748.     ExtractSubDataBlock = Results
  749. END FUNCTION
  750.  
  751. SUB CreateCardList(hDlg AS DWORD, JsonFile AS STRING)
  752. LOCAL Cards(), Lists()          AS STRING
  753. LOCAL CardIndex, idShort        AS LONG
  754. LOCAL Work, FileName            AS STRING
  755. LOCAL Details, cIndex           AS LONG
  756. LOCAL SimpleList                    AS LONG
  757.  
  758. LOCAL ThisId, StatusText            AS STRING
  759. LOCAL shortUrl, idList              AS STRING
  760. LOCAL CardName, CardDesc, CardDate  AS STRING
  761. LOCAL UrlCardName                   AS STRING
  762. LOCAL DataBlock, CardLabels         AS STRING
  763. LOCAL CardColor, CardList           AS STRING
  764.  
  765. LOCAL ListLabel, DoExtract          AS LONG
  766. LOCAL WantList(), WantLabel()       AS STRING
  767. LOCAL iCount, iCheck, iBump         AS LONG
  768. LOCAL HasAttachment                 AS STRING
  769.  
  770.  
  771.     REDIM WantList(0)
  772.     REDIM WantLabel(0)
  773.     IF (hCustom = 0) THEN
  774.         StatusText = "Creating Card List"
  775.         LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  776.     ELSE
  777.         WINDOW GET PARENT hCustom TO hDlg
  778.         StatusText = "Creating Custom List"
  779.         LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  780.         ' if 1 then List first, Label second, else the other way
  781.        CONTROL GET CHECK hCustom, %IDOPT_LISTORDER1 TO ListLabel
  782.         DIALOG GET USER hCustom, 1 TO iCount
  783.         iBump = 0
  784.         FOR cIndex = 0 TO iCount
  785.             CONTROL GET CHECK hCustom, %IDCK_LISTS + cIndex TO iCheck
  786.             IF (iCheck <> 0) THEN
  787.                 CONTROL GET TEXT hCustom, %IDCK_LISTS + cIndex TO Work
  788.                 REDIM PRESERVE WantList(iBump)
  789.                 WantList(iBump) = Work
  790.                 INCR iBump
  791.             END IF
  792.         NEXT cIndex
  793.         DIALOG GET USER hCustom, 2 TO iCount
  794.         iBump = 0
  795.         FOR cIndex = 0 TO iCount
  796.             CONTROL GET CHECK hCustom, %IDCK_LABELS + cIndex TO iCheck
  797.             IF (iCheck <> 0) THEN
  798.                 CONTROL GET TEXT hCustom, %IDCK_LABELS + cIndex TO Work
  799.                 REDIM PRESERVE WantLabel(iBump)
  800.                 WantLabel(iBump) = Work
  801.                 INCR iBump
  802.             END IF
  803.         NEXT cIndex
  804.         DIALOG END hCustom
  805.         hCustom = 0
  806.     END IF
  807.  
  808.     CardIndex = 0
  809.     REDIM Cards(CardIndex)
  810.     StatusText = "Loading Cards"
  811.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  812.     DIALOG DOEVENTS
  813.     FetchDataSet hDlg, JsonFile, "\cards.mbox", Cards()
  814.     IF (UBOUND(Cards) = 0) THEN
  815.         STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Card Extraction"
  816.         EXIT SUB
  817.     END IF
  818.     FOR CardIndex = 0 TO UBOUND(Cards)
  819.         idShort = VAL(ExtractItemValue("idShort", Cards(CardIndex)))
  820.         Cards(CardIndex) = FORMAT$(idShort, "000")  & Cards(CardIndex)
  821.     NEXT CardIndex
  822.     ARRAY SORT Cards(), ASCEND
  823.  
  824.     REDIM Lists(0)
  825.     StatusText = "Loading Lists"
  826.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  827.     DIALOG DOEVENTS
  828.     FetchDataSet hDlg, JsonFile, "\lists.mbox", Lists()
  829.  
  830.     Details = FREEFILE
  831.     FileName = JsonFile
  832.     REPLACE ".json" WITH "-cardlist.htm" IN FileName
  833.     OPEN FileName FOR OUTPUT AS Details
  834.  
  835.     PRINT #Details, "<head>"
  836.     PRINT #Details, "<title>List of Trello Cards Ordered By ID</title>"
  837.     PRINT #Details, "<style>"
  838.     PRINT #Details, "<!--"
  839.     PRINT #Details, ".green-label { background-color: #34B27D; width: 100% }"
  840.     PRINT #Details, ".yellow-label { background-color: #DBDB57; width: 100% }"
  841.     PRINT #Details, ".orange-label { background-color: #E09952; width: 100% }"
  842.     PRINT #Details, ".red-label   { background-color: #CB4D4D; width: 100% }"
  843.     PRINT #Details, ".purple-label { background-color: #9933CC; width: 100% }"
  844.     PRINT #Details, ".blue-label  { background-color: #4D77CB; width: 100% }"
  845.     PRINT #Details, "-->"
  846.     PRINT #Details, "</style>"
  847.     PRINT #Details, "</head>"
  848.     PRINT #Details, "<body>"
  849.     ' PRINT #Details, FormatHtml("<table border=|1| width=|100%|>")
  850.  
  851.  
  852.     FOR CardIndex = 0 TO UBOUND(Cards)
  853.         IF (LEN(Cards(CardIndex)) > 0) THEN
  854.             ThisId = ExtractItemValue("idShort", Cards(CardIndex))
  855.             StatusText = "Printing Card "& ThisID
  856.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  857.             DIALOG DOEVENTS
  858.  
  859.             CardLabels = "<br />"
  860.             IF (ExtractItemValue("labels", Cards(CardIndex)) = "[") THEN
  861.                 DataBlock = ExtractDataBlock("labels", Cards(CardIndex))
  862.                 cIndex = 1 ' we break on the closing curly bracket
  863.                DO
  864.                     Work = PARSE$(DataBlock, "}", cIndex)
  865.                     CardColor = Simple(ExtractItemValue("labels.color", Work))
  866.                     IF (LEN(CardColor) = 0) THEN EXIT DO
  867.                     CardLabels = CardLabels _
  868.                         &"<div class=|"& CardColor &"-label|>" _
  869.                         & Simple(ExtractItemValue("labels.name", Work)) &"</div>"
  870.                     INCR cIndex
  871.                 LOOP
  872.             END IF
  873.  
  874.             idList = Simple(ExtractItemValue("idList", Cards(CardIndex)))
  875.             CardList = "<br>List not found"
  876.             FOR cIndex = 0 TO UBOUND(Lists)
  877.                 IF (idList = Simple(ExtractItemValue("id", Lists(cIndex)))) THEN
  878.                     CardList = "<br>"& Simple(ExtractItemValue("name", Lists(cIndex)))
  879.                 END IF
  880.             NEXT cIndex
  881.  
  882.             IF ((LEN(WantList(0)) = 0) AND (LEN(WantLabel(0)) = 0)) THEN
  883.                 DoExtract = %TRUE
  884.             ELSE
  885.                 DoExtract = %FALSE
  886.                 IF ((LEN(WantList(0)) = 0) OR (LEN(WantLabel(0)) = 0)) THEN
  887.                     ' order checking don't matter, it's either one or the other
  888.                    IF (LEN(WantList(0)) = 0) THEN
  889.                         ' it's the Labels we're checking
  890.                        FOR cIndex = 0 TO UBOUND(WantLabel)
  891.                             IF (INSTR(CardLabels, WantLabel(cIndex)) > 0) THEN
  892.                                 DoExtract = %TRUE
  893.                                 EXIT FOR
  894.                             END IF
  895.                         NEXT cIndex
  896.                     ELSE
  897.                         ' it's the List that we're checking
  898.                        FOR cIndex = 0 TO UBOUND(WantList)
  899.                             IF (INSTR(CardList, WantList(cIndex)) > 0) THEN
  900.                                 DoExtract = %TRUE
  901.                                 EXIT FOR
  902.                             END IF
  903.                         NEXT cIndex
  904.                     END IF
  905.                 ELSE
  906.                     ' order checking matters, if not found in the first desired, exit false
  907.                    IF (ListLabel = 0) THEN ' labels then lists
  908.                        FOR cIndex = 0 TO UBOUND(WantLabel)
  909.                             IF (INSTR(CardLabels, WantLabel(cIndex)) > 0) THEN
  910.                                 EXIT FOR
  911.                             END IF
  912.                         NEXT cIndex
  913.                         IF (cIndex <= UBOUND(WantLabel)) THEN
  914.                             FOR cIndex = 0 TO UBOUND(WantList)
  915.                                 IF (INSTR(CardList, WantList(cIndex)) > 0) THEN
  916.                                     DoExtract = %TRUE
  917.                                     EXIT FOR
  918.                                 END IF
  919.                             NEXT cIndex
  920.                         END IF
  921.                     ELSE ' lists then labels
  922.                        FOR cIndex = 0 TO UBOUND(WantList)
  923.                             IF (INSTR(CardList, WantList(cIndex)) > 0) THEN
  924.                                 EXIT FOR
  925.                             END IF
  926.                         NEXT cIndex
  927.                         IF (cIndex <= UBOUND(WantList)) THEN
  928.                             FOR cIndex = 0 TO UBOUND(WantLabel)
  929.                                 IF (INSTR(CardLabels, WantLabel(cIndex)) > 0) THEN
  930.                                     DoExtract = %TRUE
  931.                                     EXIT FOR
  932.                                 END IF
  933.                             NEXT cIndex
  934.                         END IF
  935.                     END IF
  936.                 END IF
  937.             END IF
  938.  
  939.             IF (ISTRUE DoExtract) THEN
  940.                 shortUrl = Simple(ExtractItemValue("shortUrl", Cards(CardIndex)))
  941.                 CardName = PrintPretty(Simple(ExtractItemValue("name", Cards(CardIndex))))
  942.                 CardDesc = PrintPretty(ExtractItemValue("desc", Cards(CardIndex)))
  943.                 CardDate = WindowsTime(Simple(ExtractItemValue("dateLastActivity", Cards(CardIndex))))
  944.                 UrlCardName = "<a href=|"& shortUrl &"| target=|trello|>"& CardName &"</a>"
  945.                 HasAttachment = Simple(ExtractItemValue("idAttachmentCover", Cards(CardIndex)))
  946.                 IF (LEN(HasAttachment) > 0) THEN
  947.                     IF (HasAttachment <> "null")THEN
  948.                         HasAttachment = "<br />[IMG]"
  949.                     ELSE
  950.                         HasAttachment = ""
  951.                     END IF
  952.                 END IF
  953.                 ' IF ((UCASE$(Simple(ExtractItemValue("closed", Cards(CardIndex)))) = "TRUE") AND (LEN(HasAttachment) > 0)) THEN
  954.                    PRINT #Details, "<hr />"
  955.                     PRINT #Details, FormatHtml("<table border=|1| width=|100%|>")
  956.                     PRINT #Details, "<tr>"
  957.                     PRINT #Details, FormatHtml("<td width=|10%| valign=|top|>Card: "& ThisId & CardLabels & CardList & HasAttachment &"</td>")
  958.                     IF (UCASE$(Simple(ExtractItemValue("closed", Cards(CardIndex)))) = "TRUE") THEN
  959.                         PRINT #Details, FormatHtml("<td width=|90%| valign=|top| bgcolor=|#C790BA|>ARCHIVED "& CardDate &" - "& UrlCardName &"<br>")
  960.                     ELSE
  961.                         PRINT #Details, FormatHtml("<td width=|90%| valign=|top|>"& CardDate &" - "& UrlCardName &"<br>")
  962.                     END IF
  963.                     IF (LEN(CardDesc) > 0) THEN
  964.                         PRINT #Details, FormatHtml("Desc: "& CardDesc &"</td>")
  965.                         PRINT #Details, "</tr>"
  966.                     ELSE
  967.                         PRINT #Details, "</td>"
  968.                         PRINT #Details, "</tr>"
  969.                     END IF
  970.                     PRINT #Details, "</table>"
  971.  
  972.                     ' PRINT #SimpleList, FormatHtml("<table border=|1| width=|100%|>")
  973.                    ' PRINT #SimpleList, "<tr>"
  974.                    ' PRINT #SimpleList, FormatHtml("<td width=|10%| valign=|top|>Bug #"& ThisId & CardList &"</td>")
  975.                    ' PRINT #SimpleList, FormatHtml("<td width=|90%| valign=|top|>"& CardDate &" - "& CardName &"</td></tr>")
  976.                    ' PRINT #SimpleList, "</table>"
  977.                    ' PRINT #SimpleList, "<hr />"
  978.  
  979.                 ' END IF
  980.            END IF
  981.         END IF
  982.     NEXT CardIndex
  983.  
  984.     PRINT #Details, "</body>"
  985.     CLOSE Details
  986.  
  987.     FetchDataSet hDlg, JsonFile, "\cards.mbox", Cards()
  988.     ARRAY SORT Cards(), ASCEND
  989.  
  990.     SimpleList = FREEFILE
  991.     FileName = JsonFile
  992.     REPLACE ".json" WITH "-simplelist.htm" IN FileName
  993.     OPEN FileName FOR OUTPUT AS SimpleList
  994.  
  995.     PRINT #SimpleList, "<head>"
  996.     PRINT #SimpleList, "<title>Simple Bug List</title>"
  997.     PRINT #SimpleList, "</head>"
  998.     PRINT #SimpleList, "<body>"
  999.     FOR cIndex = 0 TO UBOUND(Lists)
  1000.         FOR CardIndex = 0 TO UBOUND(Cards)
  1001.             IF (LEN(Cards(CardIndex)) > 0) THEN
  1002.                 ThisId = ExtractItemValue("idShort", Cards(CardIndex))
  1003.                 idList = Simple(ExtractItemValue("idList", Cards(CardIndex)))
  1004.  
  1005.                 IF (idList = Simple(ExtractItemValue("id", Lists(cIndex)))) THEN
  1006.                     StatusText = "Printing Card "& ThisID
  1007.                     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  1008.                     DIALOG DOEVENTS
  1009.  
  1010.                     CardList = "<br>"& Simple(ExtractItemValue("name", Lists(cIndex)))
  1011.                     CardDate = WindowsTime(Simple(ExtractItemValue("dateLastActivity", Cards(CardIndex))))
  1012.                     CardName = PrintPretty(Simple(ExtractItemValue("name", Cards(CardIndex))))
  1013.  
  1014.                     PRINT #SimpleList, FormatHtml("Bug #"& ThisId & CardList &"<br />")
  1015.                     PRINT #SimpleList, FormatHtml(CardDate &" - "& CardName &"<br />")
  1016.                     PRINT #SimpleList, "<br />"
  1017.  
  1018.                     Cards(CardIndex) = ""
  1019.                 END IF
  1020.             END IF
  1021.         NEXT CardIndex
  1022.     NEXT cIndex
  1023.  
  1024.     PRINT #SimpleList, "</body>"
  1025.     CLOSE SimpleList
  1026.  
  1027.     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  1028.  
  1029. END SUB
  1030.  
  1031.  
  1032. SUB ExtractRecentActions(hDlg AS LONG, JsonFile AS STRING)
  1033. LOCAL FileIn, FileOut, Depth    AS LONG
  1034. LOCAL LineCount, cIndex, cCount AS LONG
  1035. LOCAL ActionIndex, CardIndex    AS LONG
  1036. LOCAL ActionCount, CheckIndex   AS LONG
  1037. LOCAL idShort, exOut, upDone    AS LONG
  1038. LOCAL CardID, ThisID, idList    AS STRING
  1039. LOCAL Cards(), Actions()        AS STRING
  1040. LOCAL CheckLists(), Lists()     AS STRING
  1041. LOCAL Work, FileName            AS STRING
  1042. LOCAL rFix, nFix, shortUrl      AS STRING
  1043. LOCAL SectionPath               AS STRING
  1044. LOCAL Char, Opener, Prefix      AS STRING
  1045. LOCAL StatusText, Card          AS STRING
  1046. LOCAL Extraction                AS LONG ' boolean value
  1047.  
  1048. LOCAL CardType, CardText, CardUser          AS STRING
  1049. LOCAL CardDate, ListBefore, ListAfter       AS STRING
  1050. LOCAL CardDesc, CardName, CardData          AS STRING
  1051. LOCAL CardAttachment, CardAttachmentURL     AS STRING
  1052. LOCAL CardChecklist, CardCheckID            AS STRING
  1053. LOCAL CardCheckState, CardList              AS STRING
  1054. LOCAL CardLabels, DataBlock, CardColor      AS STRING
  1055. LOCAL HasAttachment, CardStat1, CardStat2   AS STRING
  1056.  
  1057.     SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
  1058.  
  1059.     ActionIndex = 0
  1060.     REDIM Actions(ActionIndex)
  1061.  
  1062.     FetchDataSet hDlg, JsonFile, "\actions.mbox", Actions()
  1063.  
  1064.     IF (UBOUND(Actions) = 0) THEN
  1065.         STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Action Extraction"
  1066.         EXIT SUB
  1067.     END IF
  1068.  
  1069.     FOR ActionIndex = 0 TO UBOUND(Actions)
  1070.         Actions(ActionIndex) = ExtractItemValue("date", Actions(ActionIndex))  & Actions(ActionIndex)
  1071.     NEXT ActionIndex
  1072.  
  1073.     ARRAY SORT Actions(), DESCEND
  1074.  
  1075.  
  1076.     CardIndex = 0
  1077.     REDIM Cards(CardIndex)
  1078.  
  1079.     FetchDataSet hDlg, JsonFile, "\cards.mbox", Cards()
  1080.  
  1081.     IF (UBOUND(Cards) = 0) THEN
  1082.         STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Card Extraction"
  1083.         EXIT SUB
  1084.     END IF
  1085.  
  1086.     FOR CardIndex = 0 TO UBOUND(Cards)
  1087.         idShort = VAL(ExtractItemValue("idShort", Cards(CardIndex)))
  1088.         Cards(CardIndex) = FORMAT$(idShort, "000")  & Cards(CardIndex)
  1089.     NEXT CardIndex
  1090.  
  1091.     ARRAY SORT Cards(), ASCEND
  1092.  
  1093.  
  1094.     REDIM CheckLists(0)
  1095.     FetchDataSet hDlg, JsonFile, "\checklists.mbox", CheckLists()
  1096.     REDIM Lists(0)
  1097.     FetchDataSet hDlg, JsonFile, "\lists.mbox", Lists()
  1098.  
  1099.     FileOut = FREEFILE
  1100.     FileName = PATHNAME$(PATH, JsonFile) &"actions.txt"
  1101.     OPEN FileName FOR OUTPUT AS FileOut
  1102.     PRINT #FileOut, Actions()
  1103.     CLOSE FileOut
  1104.  
  1105.     FileOut = FREEFILE
  1106.     FileName = PATHNAME$(PATH, JsonFile) &"cards.txt"
  1107.     OPEN FileName FOR OUTPUT AS FileOut
  1108.     PRINT #FileOut, Cards()
  1109.     CLOSE FileOut
  1110.  
  1111.     FileOut = FREEFILE
  1112.     FileName = PATHNAME$(PATH, JsonFile) &"checklists.txt"
  1113.     OPEN FileName FOR OUTPUT AS FileOut
  1114.     PRINT #FileOut, CheckLists()
  1115.     CLOSE FileOut
  1116.  
  1117.     StatusText = "Creating Recent"
  1118.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  1119.     DIALOG DOEVENTS
  1120.  
  1121.     ActionCount = 0
  1122.     FileOut = FREEFILE
  1123.     FileName = JsonFile
  1124.     REPLACE ".json" WITH ".htm" IN FileName
  1125.     OPEN FileName FOR OUTPUT AS FileOut
  1126.     exOut = FREEFILE
  1127.     FileName = PATHNAME$(PATH, JsonFile) &"actions-used.txt"
  1128.     OPEN FileName FOR OUTPUT AS exOut
  1129.     PRINT #FileOut, "<head>"
  1130.     PRINT #FileOut, "<title>Recent Activity</title>"
  1131.     PRINT #FileOut, "<style>"
  1132.     PRINT #FileOut, "<!--"
  1133.     PRINT #FileOut, ".green-label { background-color: #34B27D; width: 100% }"
  1134.     PRINT #FileOut, ".yellow-label { background-color: #DBDB57; width: 100% }"
  1135.     PRINT #FileOut, ".orange-label { background-color: #E09952; width: 100% }"
  1136.     PRINT #FileOut, ".red-label   { background-color: #CB4D4D; width: 100% }"
  1137.     PRINT #FileOut, ".purple-label { background-color: #9933CC; width: 100% }"
  1138.     PRINT #FileOut, ".blue-label  { background-color: #4D77CB; width: 100% }"
  1139.     PRINT #FileOut, "-->"
  1140.     PRINT #FileOut, "</style>"
  1141.     PRINT #FileOut, "</head>"
  1142.     PRINT #FileOut, "<body>"
  1143.     PRINT #FileOut, FormatHtml("<table border=|1| width=|100%|>")
  1144.     DO
  1145.         Extraction = %TRUE
  1146.         ThisID = ""
  1147.         FOR ActionIndex = 0 TO UBOUND(Actions)
  1148.             IF (LEN(Actions(ActionIndex)) > 0) THEN
  1149.                 CardType = ExtractItemValue("type", Actions(ActionIndex))
  1150.                 idShort = VAL(ExtractItemValue("data.card.idShort", Actions(ActionIndex)))
  1151.                 CardID = ExtractItemValue("data.card.id", Actions(ActionIndex))
  1152.                 IF (idShort = 425) THEN
  1153.                     idShort = idShort
  1154.                 END IF
  1155.                 IF ((ThisID = "") OR (ThisID = CardID)) THEN
  1156.                     Work = Actions(ActionIndex)
  1157.                     REPLACE $TAB WITH $CRLF & $TAB IN Work
  1158.                     PRINT #exOut, Work
  1159.                     IF (ThisId = "") THEN
  1160.                         PRINT #FileOut, "</table>"
  1161.                         PRINT #FileOut, "<hr />"
  1162.                         PRINT #FileOut, FormatHtml("<table border=|1| width=|100%|>")
  1163.                         FOR CardIndex = 0 TO UBOUND(Cards)
  1164.                             ThisId = ExtractItemValue("id", Cards(CardIndex))
  1165.                             IF (ThisID = CardID) THEN
  1166.                                 shortUrl = Simple(ExtractItemValue("shortUrl", Cards(CardIndex)))
  1167.                                 ' don't strip this, cannot use simple
  1168.                                ' CardName = PrintPretty(Simple(ExtractItemValue("name", Cards(CardIndex))))
  1169.                                CardName = PrintPretty(ExtractItemValue("name", Cards(CardIndex)))
  1170.                                 CardDesc = PrintPretty(ExtractItemValue("desc", Cards(CardIndex)))
  1171.                                 CardDate = WindowsTime(Simple(ExtractItemValue("dateLastActivity", Cards(CardIndex))))
  1172.                                 CardName = "<a href=|"& shortUrl &"| target=|trello|>"& CardName &"</a>"
  1173.                                 CardLabels = ""
  1174.                                 IF (ExtractItemValue("labels", Cards(CardIndex)) = "[") THEN
  1175.                                     DataBlock = ExtractDataBlock("labels", Cards(CardIndex))
  1176.                                     CardLabels = "<br />"
  1177.                                     cIndex = 1 ' we break on the closing curly bracket
  1178.                                    DO
  1179.                                         Work = PARSE$(DataBlock, "}", cIndex)
  1180.                                         CardColor = Simple(ExtractItemValue("labels.color", Work))
  1181.                                         IF (LEN(CardColor) = 0) THEN EXIT DO
  1182.                                         CardLabels = CardLabels _
  1183.                                             &"<div class=|"& CardColor &"-label|>" _
  1184.                                             & Simple(ExtractItemValue("labels.name", Work)) &"</div>"
  1185.                                         INCR cIndex
  1186.                                     LOOP
  1187.                                 END IF
  1188.                                 idList = Simple(ExtractItemValue("idList", Cards(CardIndex)))
  1189.                                 CardList = "<br>List not found"
  1190.                                 FOR cIndex = 0 TO UBOUND(Lists)
  1191.                                     IF (idList = Simple(ExtractItemValue("id", Lists(cIndex)))) THEN
  1192.                                         CardList = "<br>"& Simple(ExtractItemValue("name", Lists(cIndex)))
  1193.                                     END IF
  1194.                                 NEXT cIndex
  1195.                                 HasAttachment = Simple(ExtractItemValue("idAttachmentCover", Cards(CardIndex)))
  1196.                                 IF (LEN(HasAttachment) > 0) THEN
  1197.                                     IF (HasAttachment <> "null")THEN
  1198.                                         HasAttachment = "<br />[IMG]"
  1199.                                     ELSE
  1200.                                         HasAttachment = ""
  1201.                                     END IF
  1202.                                 END IF
  1203.                                 PRINT #FileOut, "<tr>"
  1204.                                 IF (UCASE$(Simple(ExtractItemValue("closed", Cards(CardIndex)))) = "TRUE") THEN
  1205.                                     CardStat1 = "<td width=|10%| valign=|top| bgcolor=|#C790BA|>ARCHIVED: "
  1206.                                     CardStat2 = "<td width=|90%| valign=|top| bgcolor=|#C790BA|>"
  1207.                                 ELSE
  1208.                                     CardStat1 = "<td width=|10%| valign=|top|>Card: "
  1209.                                     CardStat2 = "<td width=|90%| valign=|top|>"
  1210.                                 END IF
  1211.                                 PRINT #FileOut, FormatHtml(CardStat1 & FORMAT$(idShort) & CardLabels & CardList & HasAttachment &"</td>")
  1212.                                 PRINT #FileOut, FormatHtml(CardStat2 & CardDate &" - "& CardName &"<br>")
  1213.                                 IF (LEN(CardDesc) > 0) THEN
  1214.                                     PRINT #FileOut, FormatHtml("Desc: "& CardDesc &"</td>")
  1215.                                     PRINT #FileOut, "</tr>"
  1216.                                 ELSE
  1217.                                     PRINT #FileOut, "</td>"
  1218.                                     PRINT #FileOut, "</tr>"
  1219.                                 END IF
  1220.                                 Cards(CardIndex) = ""
  1221.                                 ActionCount = 0
  1222.                                 EXIT FOR
  1223.                             END IF
  1224.                         NEXT CardIndex
  1225.                     END IF
  1226.                     INCR ActionCount
  1227.                     StatusText = "Printing Card "& FORMAT$(idShort) &"."& FORMAT$(ActionCount)
  1228.                     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  1229.                     DIALOG DOEVENTS
  1230.                     ThisID = CardID
  1231.                     Extraction = %FALSE
  1232.                     CardType = ExtractItemValue("type", Actions(ActionIndex))
  1233.                     CardUser = Simple(ExtractItemValue("memberCreator.fullName", Actions(ActionIndex)))
  1234.                     CardName = PrintPretty(Simple(ExtractItemValue("data.card.name", Actions(ActionIndex))))
  1235.                     CardDate = WindowsTime(Simple(ExtractItemValue("date", Actions(ActionIndex))))
  1236.  
  1237.                     SELECT CASE CardType
  1238.  
  1239.                         CASE "|addAttachmentToCard|"
  1240.                             CardAttachmentUrl = Simple(ExtractItemValue("data.attachment.url", Actions(ActionIndex)))
  1241.                             CardAttachment = Simple(ExtractItemValue("data.attachment.name", Actions(ActionIndex)))
  1242.                             Work = "<a href=|"& CardAttachmentUrl &"| target=|trello|>"& CardAttachment &"</a>"
  1243.                             PRINT #FileOut, "<tr>"
  1244.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1245.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1246.                            IF (LEN(CardAttachmentUrl) > 0) THEN
  1247.                                 PRINT #FileOut, FormatHtml(" --- "& CardUser &" attached "& Work &"</td>")
  1248.                             ELSE
  1249.                                 PRINT #FileOut, FormatHtml(" --- "& CardUser &" attached <strike>"& CardAttachment &"</strike></td>")
  1250.                             END IF
  1251.                             PRINT #FileOut, "</tr>"
  1252.  
  1253.                         CASE "|addChecklistToCard|"
  1254.                             CardData = ExtractItemValue("data.checklist.name", Actions(ActionIndex))
  1255.                             PRINT #FileOut, "<tr>"
  1256.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1257.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1258.                            PRINT #FileOut, FormatHtml("<br>"& CardUser &" Added Checklist "& CardData)
  1259.                             CardCheckID = ExtractItemValue("data.checklist.id", Actions(ActionIndex))
  1260.                             FOR CheckIndex = 0 TO UBOUND(CheckLists)
  1261.                                 IF (ExtractItemValue("id", CheckLists(CheckIndex)) = CardCheckID) THEN
  1262.                                     PRINT #FileOut, "<ul>"
  1263.                                     cCount = PARSECOUNT(CheckLists(CheckIndex), $TAB)
  1264.                                     FOR cIndex = 1 TO cCount
  1265.                                         CardCheckList = PARSE$(CheckLists(CheckIndex), $TAB, cIndex)
  1266.                                         Work = Simple(ExtractItemValue("checkItems.state", CardCheckList))
  1267.                                         IF (LEN(Work) > 0) THEN
  1268.                                             CardCheckState = Work
  1269.                                         END IF
  1270.                                         Work = PrintPretty(ExtractItemValue("checkItems.name", CardCheckList))
  1271.                                         IF (LEN(Work) > 0) THEN
  1272.                                             IF (CardCheckState = "complete") THEN
  1273.                                                 PRINT #FileOut, FormatHtml("<li type=|square|>"& Work)
  1274.                                             ELSE
  1275.                                                 PRINT #FileOut, FormatHtml("<li type=|circle|>"& Work)
  1276.                                             END IF
  1277.                                         END IF
  1278.                                     NEXT cIndex
  1279.                                     PRINT #FileOut, "</ul>"
  1280.                                     EXIT FOR
  1281.                                 END IF
  1282.                             NEXT CheckIndex
  1283.                             IF (CheckIndex > UBOUND(CheckLists)) THEN
  1284.                                 PRINT #FileOut, "<ul>"
  1285.                                 PRINT #FileOut, "<li>Check List NOT Found"
  1286.                                 PRINT #FileOut, "</ul>"
  1287.                             END IF
  1288.                             PRINT #FileOut, "</td>"
  1289.                             PRINT #FileOut, "</tr>"
  1290.  
  1291.                         CASE "|addMemberToBoard|"
  1292.                             ' this should not be found
  1293.                            PRINT #FileOut, "<tr>"
  1294.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1295.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1296.                            PRINT #FileOut, FormatHtml(" --- "& CardUser &" Added Member To Board</td>")
  1297.  
  1298.                         CASE "|addMemberToCard|"
  1299.                             CardUser = Simple(ExtractItemValue("memberCreator.fullName", Actions(ActionIndex)))
  1300.                             CardData = Simple(ExtractItemValue("member.fullName", Actions(ActionIndex)))
  1301.                             PRINT #FileOut, "<tr>"
  1302.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1303.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1304.                            IF (CardUser = CardData) THEN
  1305.                                 PRINT #FileOut, FormatHtml(" --- "& CardUser &" Joined Card</td>")
  1306.                             ELSE
  1307.                                 PRINT #FileOut, FormatHtml(" --- "& CardUser &" added "& CardData &"</td>")
  1308.                             END IF
  1309.                             PRINT #FileOut, "</tr>"
  1310.  
  1311.                         CASE "|commentCard|"
  1312.                             CardText = PrintPretty(ExtractItemValue("data.text", Actions(ActionIndex)))
  1313.                             PRINT #FileOut, "<tr>"
  1314.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1315.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName &"<br>")
  1316.                            PRINT #FileOut, FormatHtml("Comment: "& CardUser)
  1317.                             PRINT #FileOut, FormatHtml("<p>"& CardText &"</p>")
  1318.                             PRINT #FileOut, "</td>"
  1319.                             PRINT #FileOut, "</tr>"
  1320.  
  1321.                         CASE "|copyCard|"
  1322.                             PRINT #FileOut, "<tr>"
  1323.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1324.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1325.                            CardAttachment = "From: "& _
  1326.                                 Simple(ExtractItemValue("data.cardSource.idShort", Actions(ActionIndex))) _
  1327.                                 &" To "& _
  1328.                                 Simple(ExtractItemValue("data.card.idShort", Actions(ActionIndex)))
  1329.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Copied Comment "& CardAttachment &"</td>")
  1330.                             PRINT #FileOut, "</tr>"
  1331.  
  1332.                         CASE "|copyCommentCard|"
  1333.                             PRINT #FileOut, "<tr>"
  1334.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1335.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1336.                            PRINT #FileOut, FormatHtml(" --- "& CardUser &" Copied Card</td>")
  1337.                             PRINT #FileOut, "</tr>"
  1338.  
  1339.                         CASE "|createCard|"
  1340.                             PRINT #FileOut, "<tr>"
  1341.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1342.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1343.                            PRINT #FileOut, FormatHtml(" --- "& CardUser &" Created Card</td>")
  1344.                             PRINT #FileOut, "</tr>"
  1345.  
  1346.                         CASE "|deleteAttachmentFromCard|"
  1347.                             CardAttachment = Simple(ExtractItemValue("data.attachment.name", Actions(ActionIndex)))
  1348.                             PRINT #FileOut, "<tr>"
  1349.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1350.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1351.                            PRINT #FileOut, FormatHtml(" --- "& CardUser &" deleted "& CardAttachment &"</td>")
  1352.                             PRINT #FileOut, "</tr>"
  1353.  
  1354.                         CASE "|disablePowerUp|"
  1355.                             PRINT #FileOut, "<tr>"
  1356.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1357.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1358.                            CardAttachment = Simple(ExtractItemValue("data.value", Actions(ActionIndex)))
  1359.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Disabled Powerup "& CardAttachment &"</td>")
  1360.                             PRINT #FileOut, "</tr>"
  1361.  
  1362.                         CASE "|moveCardFromBoard|"
  1363.                             PRINT #FileOut, "<tr>"
  1364.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1365.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1366.                            CardAttachment = Simple(ExtractItemValue("data.boardTarget.name", Actions(ActionIndex)))
  1367.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Moved Card To Board "& CardAttachment &"</td>")
  1368.                             PRINT #FileOut, "</tr>"
  1369.  
  1370.                         CASE "|moveCardToBoard|"
  1371.                             PRINT #FileOut, "<tr>"
  1372.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1373.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1374.                            CardAttachment = Simple(ExtractItemValue("data.boardSource.name", Actions(ActionIndex)))
  1375.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Moved Card From Board "& CardAttachment &"</td>")
  1376.                             PRINT #FileOut, "</tr>"
  1377.  
  1378.                         CASE "|removeChecklistFromCard|"
  1379.                             PRINT #FileOut, "<tr>"
  1380.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1381.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1382.                            CardData = ExtractItemValue("data.checklist.name", Actions(ActionIndex))
  1383.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Checklist "& CardData &"</td>")
  1384.                             PRINT #FileOut, "</tr>"
  1385.  
  1386.                         CASE "|removeMemberFromCard|"
  1387.                             PRINT #FileOut, "<tr>"
  1388.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1389.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1390.                            CardAttachment = Simple(ExtractItemValue("member.fullName", Actions(ActionIndex)))
  1391.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Removed Member From Card: "& CardAttachment &"</td>")
  1392.                             PRINT #FileOut, "</tr>"
  1393.  
  1394.                         CASE "|updateBoard|"
  1395.                             PRINT #FileOut, "<tr>"
  1396.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1397.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1398.                            CardAttachment = "From: "& _
  1399.                                 Simple(ExtractItemValue("data.old.prefs.cardAging", Actions(ActionIndex))) _
  1400.                                 &" To "& _
  1401.                                 Simple(ExtractItemValue("data.board.prefs.cardAging", Actions(ActionIndex)))
  1402.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Updated Board "& CardAttachment &"</td>")
  1403.                             PRINT #FileOut, "</tr>"
  1404.  
  1405.                         CASE "|updateCard|"
  1406.                             upDone = %TRUE
  1407.  
  1408.                             ListAfter = Simple(ExtractItemValue("data.listAfter.name", Actions(ActionIndex)))
  1409.                             IF (LEN(ListAfter) > 0) THEN
  1410.                                 ListBefore = Simple(ExtractItemValue("data.listBefore.name", Actions(ActionIndex)))
  1411.                                 PRINT #FileOut, "<tr>"
  1412.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1413.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1414.                                PRINT #FileOut, FormatHtml(" --- "& CardUser &" Moved Card To "& ListAfter &"</td>")
  1415.                                 PRINT #FileOut, "</tr>"
  1416.                                 upDone = %FALSE
  1417.                             END IF
  1418.  
  1419.                             ListAfter = Simple(ExtractItemValue("data.old.name", Actions(ActionIndex)))
  1420.                             IF (LEN(ListAfter) > 0) THEN
  1421.                                 PRINT #FileOut, "<tr>"
  1422.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1423.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1424.                                PRINT #FileOut, FormatHtml(" --- "& CardUser &" Edited the Card Name</td>")
  1425.                                 PRINT #FileOut, "</tr>"
  1426.                                 upDone = %FALSE
  1427.                             END IF
  1428.  
  1429.                             ListAfter = Simple(ExtractItemValue("data.old.desc", Actions(ActionIndex)))
  1430.                             IF (INSTR(Actions(ActionIndex), "|data.old.desc|") > 0) THEN
  1431.                                 PRINT #FileOut, "<tr>"
  1432.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1433.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1434.                                PRINT #FileOut, FormatHtml(" --- "& CardUser &" Edited the Card Description</td>")
  1435.                                 PRINT #FileOut, "</tr>"
  1436.                                 upDone = %FALSE
  1437.                             END IF
  1438.  
  1439.                             ListAfter = Simple(ExtractItemValue("data.old.pos", Actions(ActionIndex)))
  1440.                             IF (LEN(ListAfter) > 0) THEN
  1441.                                 PRINT #FileOut, "<tr>"
  1442.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1443.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1444.                                PRINT #FileOut, FormatHtml(" --- "& CardUser &" Edited the Card Position</td>")
  1445.                                 PRINT #FileOut, "</tr>"
  1446.                                 upDone = %FALSE
  1447.                             END IF
  1448.  
  1449.                             ListAfter = Simple(ExtractItemValue("data.old.closed", Actions(ActionIndex)))
  1450.                             IF (LEN(ListAfter) > 0) THEN
  1451.                                 PRINT #FileOut, "<tr>"
  1452.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1453.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1454.                                ListAfter = Simple(ExtractItemValue("data.card.closed", Actions(ActionIndex)))
  1455.                                 IF (UCASE$(ListAfter) = "TRUE") THEN
  1456.                                     PRINT #FileOut, FormatHtml(" --- "& CardUser &" Closed This Card</td>")
  1457.                                 ELSE
  1458.                                     PRINT #FileOut, FormatHtml(" --- "& CardUser &" Reopened This Card</td>")
  1459.                                 END IF
  1460.                                 PRINT #FileOut, "</tr>"
  1461.                                 upDone = %FALSE
  1462.                             END IF
  1463.  
  1464.                             IF (ISTRUE upDone) THEN
  1465.                                 CardData = Simple(ExtractItemValue("id", Actions(ActionIndex)))
  1466.                                 PRINT #FileOut, "<tr>"
  1467.                                 PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1468.                                 PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1469.                                PRINT #FileOut, FormatHtml(" --- "& CardUser &" updated something "& CardData &"</td>")
  1470.                                 PRINT #FileOut, "</tr>"
  1471.                             END IF
  1472.  
  1473.                             '    Work = Simple(ExtractItemValue("data.card.closed", Actions(ActionIndex)))
  1474.                            '    IF (Work = "true") THEN
  1475.                            '        PRINT #FileOut, "<tr>"
  1476.                            '        PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1477.                            '        PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1478.                            '        PRINT #FileOut, FormatHtml(" --- "& CardUser &" Closed this card.</td>")
  1479.                            '        PRINT #FileOut, "</tr>"
  1480.                            '    END IF
  1481.  
  1482.                         CASE "|updateCheckItemStateOnCard|"
  1483.                             PRINT #FileOut, "<tr>"
  1484.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1485.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1486.                            CardData = Simple(ExtractItemValue("data.card.name", Actions(ActionIndex)))
  1487.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Updated Check Item State "& CardData &"</td>")
  1488.                             PRINT #FileOut, "</tr>"
  1489.  
  1490.                         CASE "|updateChecklist|"
  1491.                             PRINT #FileOut, "<tr>"
  1492.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1493.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1494.                            CardData = Simple(ExtractItemValue("data.card.name", Actions(ActionIndex)))
  1495.                             PRINT #FileOut, FormatHtml(" --- "& CardUser &" Updated Checklist "& CardData &"</td>")
  1496.                             PRINT #FileOut, "</tr>"
  1497.  
  1498.                         CASE "|updateList|"
  1499.                             CardData = ExtractItemValue("data.checklist.name", Actions(ActionIndex))
  1500.                             PRINT #FileOut, "<tr>"
  1501.                             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& FORMAT$(idShort) &"</td>")
  1502.                             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate) ' &" - "& CardName)
  1503.                            PRINT #FileOut, FormatHtml(" --- "& CardUser &" Updated Checklist "& CardData &"</td>")
  1504.                             PRINT #FileOut, "</tr>"
  1505.  
  1506.                     END SELECT
  1507.                     Actions(ActionIndex) = ""
  1508.  
  1509.                 END IF
  1510.             END IF
  1511.         NEXT ActionIndex
  1512.         IF (ISTRUE Extraction) THEN EXIT DO
  1513.     LOOP
  1514.     PRINT #FileOut, "</table>"
  1515.  
  1516.     ' extract cards that have no recent actions
  1517.    FOR CardIndex = 0 TO UBOUND(Cards)
  1518.         IF (LEN(Cards(CardIndex)) > 0) THEN
  1519.             PRINT #FileOut, "<hr />"
  1520.             PRINT #FileOut, FormatHtml("<table border=|1| width=|100%|>")
  1521.             ThisId = ExtractItemValue("idShort", Cards(CardIndex))
  1522.             StatusText = "Printing Card "& ThisID &".0"
  1523.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  1524.             shortUrl = Simple(ExtractItemValue("shortUrl", Cards(CardIndex)))
  1525.             CardName = PrintPretty(Simple(ExtractItemValue("name", Cards(CardIndex))))
  1526.             CardDesc = PrintPretty(ExtractItemValue("desc", Cards(CardIndex)))
  1527.             CardDate = WindowsTime(Simple(ExtractItemValue("dateLastActivity", Cards(CardIndex))))
  1528.             CardName = "<a href=|"& shortUrl &"| target=|trello|>"& CardName &"</a>"
  1529.             IF (ExtractItemValue("labels", Cards(CardIndex)) = "[") THEN
  1530.                 DataBlock = ExtractDataBlock("labels", Cards(CardIndex))
  1531.                 CardLabels = "<br />"
  1532.                 cIndex = 1 ' we break on the closing curly bracket
  1533.                DO
  1534.                     Work = PARSE$(DataBlock, "}", cIndex)
  1535.                     CardColor = Simple(ExtractItemValue("labels.color", Work))
  1536.                     IF (LEN(CardColor) = 0) THEN EXIT DO
  1537.                     CardLabels = CardLabels _
  1538.                         &"<div class=|"& CardColor &"-label|>" _
  1539.                         & Simple(ExtractItemValue("labels.name", Work)) &"</div>"
  1540.                     INCR cIndex
  1541.                 LOOP
  1542.             END IF
  1543.             PRINT #FileOut, "<tr>"
  1544.             PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: "& ThisId & CardLabels &"</td>")
  1545.             PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>"& CardDate &" - "& CardName &"<br>")
  1546.             IF (LEN(CardDesc) > 0) THEN
  1547.                 PRINT #FileOut, FormatHtml("Desc: "& CardDesc &"</td>")
  1548.                 PRINT #FileOut, "</tr>"
  1549.             ELSE
  1550.                 PRINT #FileOut, "</td>"
  1551.                 PRINT #FileOut, "</tr>"
  1552.             END IF
  1553.             Cards(CardIndex) = ""
  1554.             PRINT #FileOut, "</table>"
  1555.         END IF
  1556.     NEXT CardIndex
  1557.  
  1558.     PRINT #FileOut, "</body>"
  1559.     CLOSE FileOut
  1560.     CLOSE exOut
  1561.  
  1562.     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  1563.  
  1564. END SUB
  1565.  
  1566.  
  1567. FUNCTION FormatHtml(Work AS STRING) AS STRING
  1568. DIM Results AS STRING
  1569.  
  1570.   Results = Work
  1571.   REPLACE CHR$(34) WITH "&quot;" IN Results
  1572.   REPLACE "|" WITH CHR$(34) IN Results
  1573.   REPLACE $CRLF WITH "<br />"& $CRLF IN Results
  1574.   REPLACE "<p></p>" WITH ""& $CRLF IN Results
  1575.  
  1576.   FormatHtml = Results
  1577. END FUNCTION
  1578.  
  1579.  
  1580. FUNCTION Simple(CardItem AS STRING) AS STRING
  1581. LOCAL Results       AS STRING
  1582.     Results = CardItem
  1583.     REPLACE "<" WITH "&lt;" IN Results
  1584.     REPLACE ">" WITH "&gt;" IN Results
  1585.     REPLACE "|" WITH "" IN Results
  1586.     Simple = Results
  1587. END FUNCTION
  1588.  
  1589.  
  1590. FUNCTION PrintPretty(CardItem AS STRING) AS STRING
  1591. ' this is where all the parsing and making pretty happen for those cards that need it
  1592. LOCAL Results       AS STRING
  1593.  
  1594.     ' strip trailing comma
  1595.    Results = CardItem
  1596.     IF (RIGHT$(Results, 1) = ",") THEN
  1597.         Results = LEFT$(Results, LEN(Results) - 1)
  1598.     END IF
  1599.     ' convert escaped elements
  1600.    IF (INSTR(Results, "\") > 0) THEN
  1601.         REPLACE "\n" WITH $CRLF IN Results
  1602.         REPLACE "\|" WITH "&quot;" IN Results
  1603.         REPLACE "\\`" WITH "`" IN Results
  1604.         REPLACE "\\@" WITH "@" IN Results
  1605.         REPLACE "\\#" WITH "#" IN Results
  1606.         REPLACE "\\*" WITH "*" IN Results
  1607.         REPLACE "\\" WITH "\" IN Results
  1608.     END IF
  1609.     PrintPretty = Simple(Results)
  1610. END FUNCTION
  1611.  
  1612. FUNCTION EnumerateItemNames(Hunter AS STRING, CardItem AS STRING, PriorHunter AS STRING) AS STRING
  1613. LOCAL Work  AS STRING
  1614. LOCAL TiDx  AS LONG
  1615.  
  1616.     Work = CardItem
  1617.     IF (LEN(PriorHunter) > 0) THEN
  1618.         TiDx = INSTR(Work, PriorHunter)
  1619.         Work = MID$(Work, TiDx + LEN(PriorHunter))
  1620.     END IF
  1621.     TiDx = INSTR(Work, "|"& Hunter)
  1622.     IF (TiDx = 0) THEN
  1623.         EnumerateItemNames = ""
  1624.         EXIT FUNCTION
  1625.     END IF
  1626.  
  1627.     Work = MID$(Work, TiDx)
  1628.     Work = PARSE$(Work, $TAB, 1)
  1629.     TiDx = INSTR(Work, ":")
  1630.     Work = LEFT$(Work, TiDx - 1)
  1631.  
  1632.     EnumerateItemNames = Work
  1633. END FUNCTION
  1634.  
  1635.  
  1636. SUB AnalyzeActions(hDlg AS LONG, JsonFile AS STRING)
  1637. LOCAL FileOut                   AS LONG
  1638. LOCAL ActionIndex               AS LONG
  1639. LOCAL ActionNames()             AS STRING
  1640. LOCAL ActionsSorted()           AS STRING
  1641. LOCAL Work, FileName            AS STRING
  1642. LOCAL ActionTypes, Samples      AS STRING
  1643. LOCAL StatusText                AS STRING
  1644.  
  1645. LOCAL CardType, Hunter, PriorHunter     AS STRING
  1646.  
  1647.     ActionIndex = 0
  1648.     REDIM ActionNames(ActionIndex)
  1649.     FetchDataSet hDlg, JsonFile, "\actions.mbox", ActionNames()
  1650.  
  1651.     IF (UBOUND(ActionNames) = 0) THEN
  1652.         STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Action Extraction"
  1653.     END IF
  1654.  
  1655.     FOR ActionIndex = 0 TO UBOUND(ActionNames)
  1656.         StatusText = "Analyzing Action "& FORMAT$(ActionIndex)
  1657.         STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  1658.         DIALOG DOEVENTS
  1659.         CardType = ExtractItemValue("type", ActionNames(ActionIndex))
  1660.         IF (INSTR(ActionTypes, CardType) = 0) THEN
  1661.             ActionTypes = ActionTypes & CardType
  1662.         END IF
  1663.         IF (CardType = "|updateCard|") THEN
  1664.             Hunter = "data"
  1665.             PriorHunter = ""
  1666.             DO
  1667.                 Work = EnumerateItemNames(Hunter, ActionNames(ActionIndex), PriorHunter)
  1668.                 IF (LEN(Work) = 0) THEN EXIT DO
  1669.                 PriorHunter = Work
  1670.                 IF (INSTR(Samples, Work) = 0) THEN
  1671.                     Samples = Samples & Work &":"& ExtractItemValue(Simple(Work), ActionNames(ActionIndex)) & $TAB
  1672.                 END IF
  1673.             LOOP
  1674.         END IF
  1675.     NEXT ActionIndex
  1676.  
  1677.     FileOut = FREEFILE
  1678.     FileName = PATHNAME$(PATH, JsonFile) &"analyze.txt"
  1679.     OPEN FileName FOR OUTPUT AS FileOut
  1680.     REPLACE "||" WITH "|"& $TAB &"|" IN ActionTypes
  1681.     ActionIndex = PARSECOUNT(ActionTypes, $TAB)
  1682.     REDIM ActionsSorted(ActionIndex - 1)
  1683.     PARSE ActionTypes, ActionsSorted(), $TAB
  1684.     ARRAY SORT ActionsSorted()
  1685.     FOR ActionIndex = 0 TO UBOUND(ActionsSorted)
  1686.         Work = ActionsSorted(ActionIndex)
  1687.         IF (LEN(Work) > 0) THEN
  1688.             PRINT #FileOut, Work
  1689.         END IF
  1690.     NEXT ActionIndex
  1691.  
  1692.     ActionIndex = 1
  1693.     DO
  1694.         Work = PARSE$(Samples, $TAB, ActionIndex)
  1695.         IF (LEN(Work) = 0) THEN EXIT DO
  1696.         PRINT #FileOut, Work
  1697.         INCR ActionIndex
  1698.     LOOP
  1699.  
  1700.     CLOSE FileOut
  1701.     STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
  1702.  
  1703. END SUB
  1704.  
  1705.  
  1706. SUB FetchDataSet(hDlg AS DWORD, JsonFile AS STRING, BoxName AS STRING, BYREF DataItems() AS STRING)
  1707. LOCAL FileIn, DataIndex, Depth      AS LONG
  1708. LOCAL wIndex, idShort               AS LONG
  1709. LOCAL StatusText                    AS STRING
  1710. LOCAL SectionPath, Work, Card       AS STRING
  1711. LOCAL nFix, Prefix, Char, Opener    AS STRING
  1712.  
  1713.     SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
  1714.     FileIn = FREEFILE
  1715.     OPEN SectionPath & BoxName FOR INPUT AS FileIn
  1716.     ' dispose of first item, do until depth=2
  1717.    LINE INPUT #FileIn, Work
  1718.     StatusText = "Reading "& BoxName
  1719.     LISTBOX ADD hDlg, %IDLB_CARDS, StatusText
  1720.     DIALOG DOEVENTS
  1721.  
  1722.     DataIndex = 0
  1723.     REDIM DataItems(DataIndex)
  1724.  
  1725.     DO
  1726.         LINE INPUT #FileIn, Work
  1727.         Depth = VAL(Work)
  1728.         IF (Depth = 2) THEN EXIT DO
  1729.         Work = TRIM$(MID$(Work, 2))
  1730.         REPLACE CHR$(34) WITH "|" IN Work
  1731.         nFix = PARSE$(Work, "|", 2)
  1732.         REPLACE "|"& nFix WITH "|"& Prefix & nFix IN Work
  1733.         Char = RIGHT$(Work, 1)
  1734.         IF ((Char = ":") OR (Char = "[")) THEN
  1735.             Prefix = Prefix & nFix &"."
  1736.             Opener = Opener & Char
  1737.         END IF
  1738.         Char = LEFT$(Work, 1)
  1739.         IF ((Char = "]") AND (RIGHT$(Opener, 1) = "[") AND (Depth > 3)) THEN
  1740.             IF (LEN(Prefix) > 0) THEN
  1741.                 wIndex = PARSECOUNT(Prefix, ".")
  1742.                 Char = PARSE$(Prefix, ".", wIndex - 1) &"."
  1743.                 REPLACE Char WITH "" IN Prefix
  1744.                 Opener = LEFT$(Opener, LEN(Opener) - 1)
  1745.             END IF
  1746.         END IF
  1747.         IF ((Char = "}") AND (RIGHT$(Opener, 1) = ":") AND (Depth > 3)) THEN
  1748.             IF (LEN(Prefix) > 0) THEN
  1749.                 wIndex = PARSECOUNT(Prefix, ".")
  1750.                 Char = PARSE$(Prefix, ".", wIndex - 1) &"."
  1751.                 REPLACE Char WITH "" IN Prefix
  1752.                 Opener = LEFT$(Opener, LEN(Opener) - 1)
  1753.             END IF
  1754.         END IF
  1755.         Card = Card & $TAB & Work
  1756.         IF ((Depth = 3) AND (INSTR(Work, "}") > 0)) THEN
  1757.             ' we are only interested in closing brackets
  1758.            StatusText = "Reading "& BoxName &": "& FORMAT$(DataIndex)
  1759.             STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
  1760.             DIALOG DOEVENTS
  1761.             REDIM PRESERVE DataItems(DataIndex)
  1762.             DataItems(DataIndex) = Card
  1763.             INCR DataIndex
  1764.             Card = ""
  1765.         END IF
  1766.     LOOP
  1767.  
  1768.     CLOSE FileIn
  1769. END SUB
  1770.  
  1771. FUNCTION GetUtcOffSet(Adjust AS LONG) AS QUAD
  1772. LOCAL tzTime        AS TIME_ZONE_INFORMATION
  1773. LOCAL iResult       AS LONG
  1774. LOCAL oTime, kTime  AS QUADTODOUBLE
  1775. LOCAL sTime         AS SYSTEMTIME
  1776. LOCAL Work          AS STRING
  1777.  
  1778.     iResult = GetTimeZoneInformation(tzTime)
  1779.     GetLocalTime sTime
  1780.     sTime.wHour = Adjust
  1781.     iResult = SystemTimeToFileTime(sTime, kTime.iParts)
  1782.     Work = "Offset From UTC: "& FORMAT$(tzTime.Bias)
  1783.     sTime.wHour = (tzTime.Bias / 60)
  1784.     iResult = SystemTimeToFileTime(sTime, oTime.iParts)
  1785.     GetUtcOffSet = oTime.iQuad - kTime.iQuad
  1786.  
  1787. END FUNCTION
  1788.  
  1789. FUNCTION MakeReadableTime(uTime AS QUAD) AS STRING
  1790. LOCAL sTime         AS SYSTEMTIME
  1791. LOCAL hTime         AS QUADTODOUBLE
  1792. LOCAL iResult       AS LONG
  1793. LOCAL Work          AS STRING
  1794.     hTime.iQuad = uTime
  1795.     iResult = FileTimeToSystemTime(hTime.iParts, sTime)
  1796.     Work = FORMAT$(sTime.wMonth)
  1797.     Work = Work &"/"& FORMAT$(sTime.wDay)
  1798.     Work = Work &"/"& FORMAT$(sTime.wYear)
  1799.     Work = Work &" "& FORMAT$(sTime.wHour, "00")
  1800.     Work = Work &":"& FORMAT$(sTime.wMinute, "00")
  1801.     Work = Work &":"& FORMAT$(sTime.wSecond, "00")
  1802.     MakeReadableTime = Work
  1803. END FUNCTION
  1804.  
  1805. FUNCTION WindowsTime(UtcTime AS STRING) AS STRING
  1806. ' 2013-11-16T04:34:44.891Z
  1807. LOCAL sTime         AS SYSTEMTIME
  1808. LOCAL hTime         AS QUADTODOUBLE
  1809. LOCAL iResult       AS LONG
  1810. LOCAL Work          AS STRING
  1811.  
  1812.     sTime.wYear     = VAL(PARSE$(PARSE$(UtcTime, "T", 1), "-", 1))
  1813.     sTime.wMonth    = VAL(PARSE$(PARSE$(UtcTime, "T", 1), "-", 2))
  1814.     sTime.wDay      = VAL(PARSE$(PARSE$(UtcTime, "T", 1), "-", 3))
  1815.     sTime.wHour     = VAL(PARSE$(PARSE$(UtcTime, "T", 2), ":", 1))
  1816.     sTime.wMinute   = VAL(PARSE$(PARSE$(UtcTime, "T", 2), ":", 2))
  1817.     sTime.wSecond   = VAL(PARSE$(PARSE$(UtcTime, "T", 2), ":", 3))
  1818.  
  1819.     iResult = SystemTimeToFileTime(sTime, hTime.iParts)
  1820.     hTime.iQuad = hTime.iQuad - GetUtcOffSet(0)
  1821.     WindowsTime = MakeReadableTime(hTime.iQuad)
  1822.  
  1823. END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment