Skip to content

Commit

Permalink
Update init.go
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLai666 committed Oct 17, 2024
1 parent 4064997 commit 87ebecf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lp/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,19 @@ func locateOrInstallGLPK_Win() (string, error) {
}

// 查找新安裝的 glpsol.exe
glpsolPath = findGLPKExecutable(installDir)
if glpsolPath == "" {
return "", fmt.Errorf("failed to find GLPK executable after installation")
glpsolPath, err = findGLPKExecutable(installDir)
if err != nil {
return "", fmt.Errorf("failed to find GLPK executable after installation: %v", err)
}

insyra.LogInfo("lp.init: GLPK installed successfully at %s", glpsolPath)
return glpsolPath, nil
}

// 動態尋找包含 w64 的資料夾
func findGLPKExecutable(baseDir string) string {
func findGLPKExecutable(baseDir string) (string, error) {
var glpkExecPath string
filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
if err == nil && info.IsDir() && filepath.Base(path) == "w64" {
potentialExecPath := filepath.Join(path, "glpsol.exe")
if _, err := os.Stat(potentialExecPath); err == nil {
Expand All @@ -286,7 +286,10 @@ func findGLPKExecutable(baseDir string) string {
}
return nil
})
return glpkExecPath
if err != nil {
return "", err
}
return glpkExecPath, nil
}

// =========================== 輔助函數 ===========================
Expand Down

0 comments on commit 87ebecf

Please sign in to comment.