開發(fā)指南:為Blender Launcher V2添加新Blender Fork支持的11個(gè)關(guān)鍵步驟)
高級(jí)開發(fā)指南為Blender Launcher V2添加新Blender Fork支持的11個(gè)關(guān)鍵步驟【免費(fèi)下載鏈接】Blender-Launcher-V2Standalone client for managing official builds of Blender 3D and its popular forks項(xiàng)目地址: https://gitcode.com/gh_mirrors/bl/Blender-Launcher-V2Blender Launcher V2 是一款可獨(dú)立運(yùn)行的客戶端用于管理官方 Blender 3D 構(gòu)建及其熱門 Fork如 Bforartists、UPBGE的下載、安裝與更新。本文為開發(fā)者提供完整指南按照 11 個(gè)關(guān)鍵步驟從零為 Blender Launcher V2 添加一個(gè)新 Blender Fork 支持覆蓋爬蟲、設(shè)置、界面、構(gòu)建處理與解壓五大層。為什么需要“Fork 支持”所謂Fork就是基于 Blender 源碼二次開發(fā)的衍生版本。要在啟動(dòng)器中支持一個(gè)新 Fork需要打通 5 個(gè)層次層次職責(zé)核心目錄1. 抓取Scraping從 Fork 官網(wǎng)/API 獲取構(gòu)建信息source/threads/scraping/2. 設(shè)置Settings提供可見性與更新行為開關(guān)source/modules/settings.py3. 界面UI創(chuàng)建 Library / Downloads 頁(yè)面source/windows/main_window/4. 構(gòu)建處理處理可執(zhí)行文件名、版本號(hào)、目錄結(jié)構(gòu)source/modules/build_info.py5. 解壓Extraction處理特殊壓縮包格式與目錄source/threads/extractor.py官方文檔中對(duì)這一步驟有完整記錄可直接對(duì)照閱讀implementing_new_fork.md。第 1 步創(chuàng)建爬蟲Scraper在source/threads/scraping/下新建fork_name.py繼承基類BuildScraper重寫scrape()生成器為每個(gè)構(gòu)建yield一個(gè)BuildInfo對(duì)象含下載地址、版本號(hào)、commit 哈希、時(shí)間、分支名、可執(zhí)行文件名?;惗x見 base.py參考現(xiàn)成實(shí)現(xiàn)bfa.pyNextcloud 源、upbge.pyGitHub Releases 源版本號(hào)解析復(fù)用 build_info.py 中的parse_blender_ver()第 2 步添加設(shè)置項(xiàng)Settings在 settings.py 中為新 Fork 增加三組函數(shù)Library 可見性get_show_xxx_builds()/set_show_xxx_builds()Downloads 抓取開關(guān)get_scrape_xxx_builds()/set_scrape_xxx_builds()更新按鈕行為get_xxx_update_behavior()等同時(shí)把新 Fork 注冊(cè)進(jìn)三個(gè)字典/列表library_pages、downloads_pages現(xiàn)有入口可參考 settings.py#L49-L68與minimum_version_table值為下一個(gè)可用索引。第 3 步接入更新管理器修改 blender_update_manager.py 中的_branch_visibility()與_get_update_behavior()讓新分支命中后返回 Fork 專屬的可見性與更新行為替換 or 雙版本并存。第 4 步注冊(cè)到總爬蟲在 scraper.py 中完成三處改動(dòng)實(shí)例化你的爬蟲如self.scraper_upbge_stable ...參考 scraper.py#L64-L71在scrapers()方法中按設(shè)置開關(guān)將其加入列表參考 scraper.py#L85-L99若 Windows 下需要按鏈接關(guān)鍵字過濾架構(gòu)在get_download_links()的 amd64 分支中補(bǔ)上fork in build.link.lower()判斷第 5 步登記 Library 掃描目錄在 library_drawer.py 的DrawLibraryTask.folders元組中加入 Fork 的庫(kù)目錄名并在get_blender_builds()中增加該 Fork 可執(zhí)行文件.exe/.app的識(shí)別判斷否則已安裝的構(gòu)建無法被識(shí)別。第 6 步創(chuàng)建主窗口 UI 頁(yè)面在source/windows/main_window/的窗口繪制邏輯中用BasePageWidget為 Library 和 Downloads 各創(chuàng)建一個(gè)Fork Name標(biāo)簽頁(yè)add_tab可傳folder或branch過濾條件語(yǔ)義見 version_matcher.py在start_scraper()中接受新的scrape_xxx參數(shù)在update_visible_lists()中根據(jù)第 2 步的設(shè)置刷新標(biāo)簽頁(yè)可見性第 7 步擴(kuò)展設(shè)置界面blender_builds_tab.py連接新 Fork 的library_changed/download_changed信號(hào)并添加“顯示更新按鈕”復(fù)選框與更新行為下拉框repo_group.py新增一個(gè)RepoUserView條目并加入self.repos列表第 8 步處理下載與解壓在 download_widget.py 的init_extractor()中為新分支指定庫(kù)目錄dist library_folder / fork-branch。若 Fork 使用非標(biāo)準(zhǔn)壓縮包結(jié)構(gòu)嵌套目錄、bin/Release等在 extractor.py 中新增一個(gè)_fix_xxx_structure()修正函數(shù)并在ExtractTask.run()末尾調(diào)用。第 9 步處理版本映射若 Fork 使用自己的版本號(hào)體系如 UPBGE 0.40 基于 Blender 4.0在 build_info.py 中編寫一個(gè)版本映射函數(shù)把 Fork 版本映射到對(duì)應(yīng)的 Blender 配置版本并暴露為BuildInfo的屬性供 .blend 文件版本匹配使用。第 10 步注冊(cè)配置文件夾路徑Fork 專屬的配置路徑集中在 build_info.py 的FORK_CONFIG_PATHS字典中現(xiàn)有條目見 build_info.py#L38-L51結(jié)構(gòu)為fork-branch: { config_folder: 組織名, # 僅 Windows%APPDATA% 下 config_subfolder: 子目錄, # 或按平臺(tái)區(qū)分的字典 }若該 Fork 支持便攜模式還需在 library_widget.py 的make_portable_path()中補(bǔ)充邏輯。第 11 步從 Fork 源碼中定位真實(shí)配置路徑這一步是第 10 步的依據(jù)。打開 Fork 倉(cāng)庫(kù)的三份平臺(tái)系統(tǒng)路徑文件intern/ghost/intern/GHOST_SystemPathsUnix.ccLinuxintern/ghost/intern/GHOST_SystemPathsWin32.ccWindowsintern/ghost/intern/GHOST_SystemPathsCocoa.mmmacOS在每份文件中查找getUserDir()函數(shù)提取平臺(tái)提取內(nèi)容示例LinuxXDG_CONFIG_HOME回退路徑中的目錄名~/.config/upbge/0.40/Windows%APPDATA%下的組織名 應(yīng)用子目錄%APPDATA%\UPBGE\Blender\0.40\macOSGetApplicationSupportDir()中的目錄名~/Library/Application Support/UPBGE/0.40/驗(yàn)收清單如何確認(rèn) Fork 支持完成? 設(shè)置窗口中可獨(dú)立開關(guān) Library / Downloads 可見性? Downloads 頁(yè)能列出該 Fork 的構(gòu)建Windows 下按架構(gòu)正確過濾? 下載完成后自動(dòng)解壓到獨(dú)立目錄并出現(xiàn)在 Library? 雙擊可正常啟動(dòng)可執(zhí)行文件名識(shí)別正確? 已安裝構(gòu)建的 .blend 文件版本匹配走正確配置版本? 更新按鈕行為替換/并存按設(shè)置生效關(guān)鍵文件速查表組件文件路徑爬蟲source/threads/scraping/設(shè)置source/modules/settings.py更新管理source/modules/blender_update_manager.py構(gòu)建信息與配置路徑source/modules/build_info.py庫(kù)掃描source/threads/library_drawer.py主窗口頁(yè)面source/windows/main_window/設(shè)置 UIsource/windows/settings_window/blender_builds_tab.py倉(cāng)庫(kù)組控件source/widgets/repo_group.py下載/解壓source/widgets/download_widget.py、source/threads/extractor.py更多 Fork 背景資料可參考 blender_forks.md 與開發(fā)手冊(cè) development.md?!久赓M(fèi)下載鏈接】Blender-Launcher-V2Standalone client for managing official builds of Blender 3D and its popular forks項(xiàng)目地址: https://gitcode.com/gh_mirrors/bl/Blender-Launcher-V2創(chuàng)作聲明:本文部分內(nèi)容由AI輔助生成(AIGC),僅供參考