@@ -80,7 +80,6 @@ func installCEFFramework(config *remotecfg.TConfig, cmdConfig *command.Config) (
8080 lclItem = lclCfg .Item (liblclModuleVersion )
8181 // 当前安装下载源
8282 cefDownloadItem = config .ModeBaseConfig .DownloadSourceItem .CEF .Item (cefItem .DownloadSource )
83- lclDownloadItem = config .ModeBaseConfig .DownloadSourceItem .LCL .Item (lclItem .DownloadSource )
8483 )
8584 if cefModuleVersion == "" || liblclModuleVersion == "" {
8685 return "" , nil , errors .New ("CEF module " + cefModuleName + " is not configured in the current version" )
@@ -105,26 +104,73 @@ func installCEFFramework(config *remotecfg.TConfig, cmdConfig *command.Config) (
105104 downloadCefURL = strings .ReplaceAll (downloadCefURL , "{OSARCH}" , libCEFOS )
106105 downloads [consts .CefKey ] = & downloadInfo {fileName : common .UrlName (downloadCefURL ), downloadPath : filepath .Join (cmdConfig .Install .Path , consts .FrameworkCache , common .UrlName (downloadCefURL )), frameworkPath : installPathName , url : downloadCefURL , module : cefModuleName }
107106 }
107+ // LibLCL 动态链接库 下载地址, 在下面下载失败时自动切换下一个下载源使用
108+ var getLibLCLDownUrl func () string
108109 if ! isLCL {
109110 // liblcl 当前模块版本支持系统
110111 libEnergyOS := common .LibLCLOS (cmdConfig )
111112 useLibLCLModuleNameGTK3 := common .LibLCLLinuxUseGTK3 (cmdConfig .Install .OS , cmdConfig .Install .WS , liblclModuleName , moduleVersion )
112113 // https://www.xxx.xxx/xxx/releases/download/{version}/{module}.{OSARCH}.zip
113- downloadEnergyURL := lclDownloadItem .Url
114- downloadEnergyURL = strings .ReplaceAll (downloadEnergyURL , "{version}" , "v" + liblclModuleVersion )
115- downloadEnergyURL = strings .ReplaceAll (downloadEnergyURL , "{module}" , useLibLCLModuleNameGTK3 )
116- downloadEnergyURL = strings .ReplaceAll (downloadEnergyURL , "{OSARCH}" , libEnergyOS )
114+ downSrcList := lclItem .DownloadSourceList [:]
115+ // 默认使用下载源
116+ useDownSrc := lclItem .DownloadSource
117+ // 删除当前使用下载源,以在失败情况下可以获取下一个
118+ removeDownSrcForListAndSetNext := func () {
119+ for i , v := range downSrcList {
120+ if v == useDownSrc {
121+ // 删除这个
122+ downSrcList = append (downSrcList [:i ], downSrcList [i + 1 :]... )
123+ break
124+ }
125+ }
126+ // 重新设置下载源,如果下载失败
127+ if len (downSrcList ) > 0 {
128+ useDownSrc = downSrcList [0 ]
129+ }
130+ }
131+ // 获取 LibLCL 下载源,返回空表示已经被全部使用过了
132+ getLibLCLDownUrl = func () string {
133+ if len (downSrcList ) == 0 {
134+ return ""
135+ }
136+ lclDownloadItem := config .ModeBaseConfig .DownloadSourceItem .LCL .Item (useDownSrc )
137+ downloadURL := lclDownloadItem .Url
138+ downloadURL = strings .ReplaceAll (downloadURL , "{version}" , "v" + liblclModuleVersion )
139+ downloadURL = strings .ReplaceAll (downloadURL , "{module}" , useLibLCLModuleNameGTK3 )
140+ downloadURL = strings .ReplaceAll (downloadURL , "{OSARCH}" , libEnergyOS )
141+ // 删除 downSrcList 当前下载源,表示已经使用过
142+ // 将当前使用的在 下载集合里 删除掉
143+ removeDownSrcForListAndSetNext ()
144+ return downloadURL
145+ }
146+ // 获取下载地址
147+ downloadEnergyURL := getLibLCLDownUrl ()
117148 downloads [consts .LiblclKey ] = & downloadInfo {fileName : common .UrlName (downloadEnergyURL ), downloadPath : filepath .Join (cmdConfig .Install .Path , consts .FrameworkCache , common .UrlName (downloadEnergyURL )), frameworkPath : installPathName , url : downloadEnergyURL , module : liblclModuleName }
118149 }
119150 // 在线下载 CEF 框架二进制包
120151 var sortsKeys = []string {consts .LiblclKey , consts .CefKey }
121- for _ , key := range sortsKeys {
152+ for i := 0 ; i < len (sortsKeys ); i ++ {
153+ key := sortsKeys [i ]
122154 dl , ok := downloads [key ]
123155 if ok {
124156 term .Section .Println ("Download" , key , ":" , dl .url )
125157 err := tools .DownloadFile (dl .url , dl .downloadPath , env .GlobalDevEnvConfig .Proxy , nil )
126- if err != nil {
127- return "" , nil , errors .New ("Download [" + dl .fileName + "] " + err .Error ())
158+ if key == consts .LiblclKey {
159+ if err != nil {
160+ // 失败尝试使用下个下载源
161+ if downURL := getLibLCLDownUrl (); downURL != "" {
162+ term .Logger .Error ("Download" , term .Logger .Args ("ERROR" , err .Error (), "Auto switch download source" , downURL ))
163+ dl .url = downURL
164+ i --
165+ continue
166+ } else {
167+ return "" , nil , errors .New ("Download [" + dl .fileName + "] " + err .Error ())
168+ }
169+ }
170+ } else {
171+ if err != nil {
172+ return "" , nil , errors .New ("Download [" + dl .fileName + "] " + err .Error ())
173+ }
128174 }
129175 dl .success = err == nil
130176 }
0 commit comments