Browse Source

warehouse alpha

cuu 4 years ago
parent
commit
46b67bc12f
3 changed files with 129 additions and 86 deletions
  1. 94 60
      Menu/GameShell/21_Warehouse/__init__.py
  2. 34 25
      sys.py/appinstaller.py
  3. 1 1
      sys.py/pyaria2_rpc

+ 94 - 60
Menu/GameShell/21_Warehouse/__init__.py

@@ -9,7 +9,7 @@ import gobject
 import sqlite3
 #from beeprint import pp
 from libs.roundrects import aa_round_rect
-from shutil import copyfile
+from shutil import copyfile,rmtree
 
 ## local UI import
 from UI.constants import Width,Height,ICON_TYPES,RESTARTUI
@@ -372,7 +372,7 @@ class Aria2DownloadProcessPage(Page):
     
     def CheckDownload(self,aria2_gid):
         self._GID = aria2_gid 
-        self._DownloaderTimer = gobject.timeout_add(123, self.GObjectUpdateProcessInterval)
+        self._DownloaderTimer = gobject.timeout_add(234, self.GObjectUpdateProcessInterval)
         
     def KeyDown(self,event):
         if IsKeyMenuOrB(event.key):
@@ -461,7 +461,7 @@ class GameStoreListItem(InfoPageListItem):
         appdling_icon._ImgSurf = MyIconPool.GiveIconSurface("appdling")
         appdling_icon._CanvasHWND = self._CanvasHWND
         appdling_icon._Parent = self
-        app_icon.Init(0,0,MyIconPool.Width("appdling"),MyIconPool.Height("appdling"),0)
+        appdling_icon.Init(0,0,MyIconPool.Width("appdling"),MyIconPool.Height("appdling"),0)
 
         blackheart_icon = IconItem()
         blackheart_icon._ImgSurf = MyIconPool.GiveIconSurface("blackheart")
@@ -518,7 +518,7 @@ class GameStoreListItem(InfoPageListItem):
             self._Labels["Small"].Draw()
         
 
-        #pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
+        pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
  
 
 class GameStorePage(Page):
@@ -540,6 +540,8 @@ class GameStorePage(Page):
     _Downloading = None
     _aria2_db = "aria2tasks.db"
     _warehouse_db = "warehouse.db"
+    _GobjTimer = -1
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
@@ -551,6 +553,23 @@ class GameStorePage(Page):
         ]
 	self._MyStack.Push(repos)
  
+    def GObjectUpdateProcessInterval(self):
+        ret = True
+        dirty = False
+        for x in self._MyList:
+            if x._Type == "launcher" or x._Type == "pico8" or x._Type == "tic80":
+                percent = config.RPC.getPercent(x._Value["file"])
+                if percent is not None:
+                    x.SetSmallText(str(percent)+"%")
+                    dirty = True
+                else:
+                    x.SetSmallText("")
+
+        if self._Screen.CurPage() == self and dirty == True:
+            self._Screen.Draw()
+            self._Screen.SwapAndShow()
+
+        return ret
 
     def SyncWarehouse(self):
         try:
@@ -617,14 +636,22 @@ class GameStorePage(Page):
             li._PosY   = start_y + last_height
             li._Width  = Width
             li._Fonts["normal"] = self._ListFont15
+            li._Fonts["small"]  = self._ListFont12
             li._Active = False
             li._ReadOnly = True
             li._Value = u
             li._Type = u["type"]
             li.Init( u["title"] )
-
+            
             if stk_lev >1:
-                li._ReadOnly = False
+                remote_file_url = u["file"]
+                menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
+                local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
+
+                if FileExists(local_menu_file):
+                    li._ReadOnly = False
+                else:
+                    li._ReadOnly = True
             elif stk_lev == 1:
                 if "status" in u:
                     if u["status"] == "complete":
@@ -635,6 +662,9 @@ class GameStorePage(Page):
 
             last_height += li._Height
             
+            if li._Type == "launcher" or li._Type == "pico8" or li._Type == "tic80":
+                li.SetSmallText("")
+            
             self._MyList.append(li)
 
         
@@ -703,12 +733,18 @@ class GameStorePage(Page):
             remote_file_url = cur_li._Value["file"]
             menu_file = remote_file_url.split("raw.githubusercontent.com")[1] #assume master branch
             local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
-            print(local_menu_file)
+            local_menu_file_path = os.path.dirname(local_menu_file)
+            print(local_menu_file_path)
+            local_jsons = glob.glob(local_menu_file_path+"/**/*.json")
             try:
                 if os.path.exists(local_menu_file):
                     os.remove(local_menu_file)
                 if os.path.exists(local_menu_file+".aria2"):
                     os.remove(local_menu_file+".aria2")
+
+                for x in local_jsons:
+                    os.remove(x)
+
             except Exception as ex:
                 print(ex)
 
@@ -733,11 +769,12 @@ class GameStorePage(Page):
             return
         cur_li = self._MyList[self._PsIndex]
         if cur_li._Value["type"] == "launcher" or cur_li._Value["type"] == "pico8" or cur_li._Value["type"] == "tic80":
-            print(cur_li._Value["shots"])
-            self._PreviewPage._URL = cur_li._Value["shots"]
-            self._Screen.PushPage(self._PreviewPage)
-            self._Screen.Draw()
-            self._Screen.SwapAndShow()
+            if "shots" in cur_li._Value:
+                print(cur_li._Value["shots"])
+                self._PreviewPage._URL = cur_li._Value["shots"]
+                self._Screen.PushPage(self._PreviewPage)
+                self._Screen.Draw()
+                self._Screen.SwapAndShow()
 
 
     def RemoveGame(self):
@@ -760,33 +797,27 @@ class GameStorePage(Page):
                 conn.close()
             except Exception as ex:
                 print(ex)
-        elif "gid" in cur_li._Value:
-            try:
-                gid = cur_li._Value["gid"]
-                conn = sqlite3.connect(self._aria2_db)
-                conn.row_factory = dict_factory
-                c = conn.cursor()
-                ret = c.execute("SELECT * FROM tasks WHERE gid='%s'" % gid ).fetchone()
-                if ret != None:
-                    remote_file_url = ret["file"]
-                    menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
-                    local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
-                    try:
-                        if os.path.exists(local_menu_file):
-                            os.remove(local_menu_file)
-                        if os.path.exists(local_menu_file+".aria2"):
-                            os.remove(local_menu_file+".aria2")
-                    except Exception as ex:
-                        print(ex)
-
+        elif cur_li._Value["type"] == "launcher" or cur_li._Value["type"] == "pico8" or cur_li._Value["type"] == "tic80":  
+            remote_file_url = cur_li._Value["file"]
+            menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
+            local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
+            local_menu_file_path = os.path.dirname(local_menu_file)
+            
+            gid,ret = config.RPC.urlDownloading(remote_file_url)
+            if ret == True:
+                config.RPC.remove(gid)
 
-                c.execute("DELETE FROM tasks WHERE gid = '%s'" % gid )
-                conn.commit()
-                conn.close()
+            try:
+                if os.path.exists(local_menu_file):
+                    os.remove(local_menu_file)
+                if os.path.exists(local_menu_file+".aria2"):
+                    os.remove(local_menu_file+".aria2")
+                if os.path.exists( os.path.join(local_menu_file_path,cur_li._Value["title"])):
+                    rmtree(os.path.join(local_menu_file_path,cur_li._Value["title"]) )
+                
             except Exception as ex:
                 print(ex)
-        
-      
+       
     def Click(self):
         if self._PsIndex > len(self._MyList) -1:
             return
@@ -839,6 +870,7 @@ class GameStorePage(Page):
                     gid = config.RPC.addUri( remote_file_url, options={"out": menu_file})
 		    self._Downloading = gid
                     print("stack length ",self._MyStack.Length())
+                    """
                     if self._MyStack.Length() > 1:## not on the top list page
                         try:
                             conn = sqlite3.connect(self._aria2_db)
@@ -849,6 +881,7 @@ class GameStorePage(Page):
                             conn.close()
                         except Exception as ex:
                             print("SQLITE3 ",ex)
+                    """
                 else:
                     print(config.RPC.tellStatus(gid,["status","totalLength","completedLength"]))
 
@@ -863,7 +896,8 @@ class GameStorePage(Page):
             else:
                 print("file downloaded")# maybe check it if is installed,then execute it
                 if cur_li._Value["type"]=="launcher" and cur_li._ReadOnly == False:
-                    game_sh = os.path.join( "%s/apps/Menu/21_Indie Games/" % os.path.expanduser('~'),cur_li._Value["title"],cur_li._Value["title"]+".sh")
+                    local_menu_file_path = os.path.dirname(local_menu_file)
+                    game_sh = os.path.join( local_menu_file_path, cur_li._Value["title"],cur_li._Value["title"]+".sh")
                     #game_sh = reconstruct_broken_string( game_sh)
                     print("run game: ",game_sh, os.path.exists(  game_sh))
                     self._Screen.RunEXE(game_sh)
@@ -928,6 +962,8 @@ class GameStorePage(Page):
                     c.execute(sql_insert)
                     conn.commit()
                     self.SyncList()
+                    self._Screen.Draw()
+                    self._Screen.SwapAndShow()
             conn.close()
         except Exception as ex:
             print(ex)
@@ -942,9 +978,11 @@ class GameStorePage(Page):
             self._FootMsg[2] = "Remove"
             self._FootMsg[1] = "UpdateWare"
         else:
-            self._FootMsg[2] = "Up"
-            self._FootMsg[1] = ""
-
+            self._FootMsg[2] = "Remove"
+            self._FootMsg[1] = "Preview"
+        
+        self._GobjTimer = gobject.timeout_add(500, self.GObjectUpdateProcessInterval)
+        
         self.SyncList()
  
     def OnReturnBackCb(self):
@@ -953,8 +991,8 @@ class GameStorePage(Page):
             self._FootMsg[2] = "Remove"
             self._FootMsg[1] = "UpdateWare"
         else:
-            self._FootMsg[2] = ""
-            self._FootMsg[1] = ""
+            self._FootMsg[2] = "Remove"
+            self._FootMsg[1] = "Preview"
 
         self.SyncList()
         self._Screen.Draw()
@@ -974,7 +1012,7 @@ class GameStorePage(Page):
                    self._FootMsg[2] = "Remove"
                    self._FootMsg[1] = "UpdateWare"
                else:
-                   self._FootMsg[2] = ""
+                   self._FootMsg[2] = "Remove"
                    self._FootMsg[1] = "Preview"
 
                self.SyncList()
@@ -985,6 +1023,7 @@ class GameStorePage(Page):
                 self.ReturnToUpLevelPage()
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
+                gobject.source_remove(self._GobjTimer)
 
         if IsKeyStartOrA(event.key):
             self.Click()
@@ -993,7 +1032,7 @@ class GameStorePage(Page):
                 self._FootMsg[2] = "Remove"
                 self._FootMsg[1] = "UpdateWare"
             else:
-                self._FootMsg[2] = ""
+                self._FootMsg[2] = "Remove"
                 self._FootMsg[1] = "Preview"
 
             self._Screen.Draw()
@@ -1002,24 +1041,19 @@ class GameStorePage(Page):
 
         if event.key == CurKeys["X"]:
             #print(self._MyStack.Length() )
-            if self._MyStack.Length() == 1 and self._PsIndex > 0:
-                self._Screen.PushPage(self._remove_page)
-                self._remove_page._StartOrA_Event = self.RemoveGame
-                self._Screen.Draw()
-                self._Screen.SwapAndShow()
+            if  self._PsIndex <= len(self._MyList) -1:
+                cur_li = self._MyList[self._PsIndex]
+                if  cur_li._Type != "dir":
+                    if self._MyStack.Length() == 1 and self._PsIndex == 0:
+                        pass
+                        #predefined source
+                    else:
+                        self._Screen.PushPage(self._remove_page)
+                        self._remove_page._StartOrA_Event = self.RemoveGame
+                        self._Screen.Draw()
+                        self._Screen.SwapAndShow()
                 return 
 
-            """
-            if self._MyStack.Length() > 1:
-               self._MyStack.Pop()
-               if self._MyStack.Length() == 1:
-                   self._FootMsg[2] = "Remove"
-                   self._FootMsg[1] = "UpdateWare"
-               else:
-                   self._FootMsg[2] = "Up"
-                   self._FootMsg[1] = "Preview"
-            """
-
             self.SyncList()
             self._Screen.Draw()
             self._Screen.SwapAndShow()

+ 34 - 25
sys.py/appinstaller.py

@@ -21,29 +21,37 @@ def dict_factory(cursor, row):
     return d
 
 @misc.threaded
-def game_install_thread(gid):
+def game_install_thread(aria2_result):
     try:
-        conn = sqlite3.connect(aria2_db)
-        conn.row_factory = dict_factory
-        c = conn.cursor()
-        ret = c.execute("SELECT * FROM tasks WHERE gid='%s'" % gid ).fetchone()
-        if ret == None:
-            conn.close()
+        #print("game_install_thread ",aria2_result)
+        if "files" in aria2_result:
+            if len(aria2_result["files"]) <= 0:
+                return
+        if "arm" not in platform.machine():
             return
 
-        c.execute("UPDATE tasks SET status='complete' WHERE gid='%s'" % gid)
-        conn.commit()
-        conn.close()
+        ret = aria2_result["files"][0]['uris']
 
-        remote_file_url = ret["file"]
+        remote_file_url = ret[0]['uri']
         menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
         local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
-        
-        if os.path.exists(local_menu_file) == True and "arm" in platform.machine():
-           gametype = ret["type"]
+        local_menu_file_path = os.path.dirname(local_menu_file)
+
+
+        if os.path.exists(local_menu_file) == True:
+
+           gametype = "launcher"
+
+           if local_menu_file.endswith(".tar.gz"):
+               gametype = "launcher"
+           if local_menu_file.endswith(".p8.png"):
+               gametype = "pico8"
+           if local_menu_file.endswith(".tic"):
+               gametype = "tic80"
+
            if gametype == "launcher":
                #tar zxvf 
-               _cmd = "tar zxvf '%s' -C %s" % (local_menu_file, "~/apps/Menu/21_Indie\ Games/")
+               _cmd = "tar zxvf '%s' -C %s" % (local_menu_file, local_menu_file_path)
                print(_cmd)
                os.system(_cmd)
            if gametype == "pico8":
@@ -57,10 +65,8 @@ def game_install_thread(gid):
 
 
     except Exception as ex:
-        print("Sqlite3 error: ",ex)
+        print("app install error: ",ex)
          
-        
-        
 
 def on_message(ws, message):
     global rpc
@@ -76,16 +82,17 @@ def on_message(ws, message):
 
     if "method" in aria2_noti and aria2_noti["method"] == "aria2.onDownloadComplete":
          gid = aria2_noti["params"][0]["gid"]
-         #msg = rpc.tellStatus(gid)
-         #ws.send(msg)
-         game_install_thread(gid)
+         msg = rpc.tellStatus(gid)
+         ws.send(msg)
+         #game_install_thread(gid)
     
     if "method" not in aria2_noti and "result" in aria2_noti:
-        if "status" in aria2_noti:
-             if aria2_noti["status"] == "error":
+        result = aria2_noti["result"]
+        if "status" in result:
+             if result["status"] == "error":
                  try:
-                     print(aria2_noti["errorMessage"])
-                     for x in aria2_noti["files"]:
+                     print(result["errorMessage"])
+                     for x in result["files"]:
                          if os.path.exists(x["path"]):
                              os.remove(x["path"])
                          if os.path.exists(x["path"]+".aria2"):
@@ -93,6 +100,8 @@ def on_message(ws, message):
 
                  except Exception as ex:
                      print(ex)
+             if result["status"] == "complete":
+                 game_install_thread(result)
 
        
 def on_error(ws, error):

+ 1 - 1
sys.py/pyaria2_rpc

@@ -1 +1 @@
-Subproject commit 864bea5ca1252bc105cac47f640f47e95c81f6fa
+Subproject commit b554bce52720629420238c3813f72a4c6554917a