| 143 | } |
| 144 | |
| 145 | func (t *Toolchain) CheckAndRepair(silent bool) error { |
| 146 | // Default folder name is the first folder name of archive name. |
| 147 | // but it can be specified by archive name. |
| 148 | folderName, _, _ := strings.Cut(t.Path, string(filepath.Separator)) |
| 149 | if t.Archive != "" { |
| 150 | folderName = fileio.Base(t.Archive) |
| 151 | } |
| 152 | |
| 153 | // Check and repair resource. |
| 154 | archiveName := expr.If(t.Archive != "", t.Archive, filepath.Base(t.Url)) |
| 155 | toolsDir := filepath.Join(t.ctx.Downloads(), "tools") |
| 156 | repair := fileio.NewRepair(t.Url, t.ctx.Downloads(), archiveName, folderName, toolsDir, t.SHA256) |
| 157 | if err := repair.CheckAndRepair(t.ctx); err != nil { |
| 158 | return err |
| 159 | } |
| 160 | |
| 161 | if !silent { |
| 162 | // Print download & extract info. |
| 163 | if t.rootDir == "" { |
| 164 | color.PrintPass("\ntoolchain: %s", "local") |
| 165 | color.PrintHint("Location: %s\n", strings.ReplaceAll(t.Url, "file:///", "")) |
| 166 | } else { |
| 167 | color.PrintPass("toolchain: %s", t.displayName) |
| 168 | color.PrintHint("Location: %s\n", t.rootDir) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | // Detect detect local installed gcc. |
| 176 | func (t *Toolchain) Detect(platformName string) error { |