-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f33086
commit 080ad8e
Showing
7 changed files
with
244 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func DownloadFile(url string, filepath string) error { | ||
// Create the file | ||
out, err := os.Create(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
// Get the data | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Write the body to file | ||
_, err = io.Copy(out, resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// Release represents a GitHub release | ||
type Release struct { | ||
TagName string `json:"tag_name"` | ||
Name string `json:"name"` | ||
Assets []struct { | ||
Name string `json:"name"` | ||
DownloadURL string `json:"browser_download_url"` | ||
} `json:"assets"` | ||
} | ||
|
||
func GetLatestRelease() (Release, error) { | ||
var release Release | ||
repoOwner := "SavageCore" | ||
repoName := "coh3-replay-manager-go" | ||
|
||
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", repoOwner, repoName) | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
return release, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
err = json.NewDecoder(resp.Body).Decode(&release) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
return release, err | ||
} | ||
|
||
return release, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package utils | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func ExtractZip(zipFile string, destPath string) error { | ||
// Open the ZIP file for reading | ||
r, err := zip.OpenReader(zipFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer r.Close() | ||
|
||
// Create the destination directory if it doesn't exist | ||
err = os.MkdirAll(destPath, 0755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Extract each file from the ZIP archive | ||
for _, f := range r.File { | ||
// Open the file in the ZIP archive | ||
rc, err := f.Open() | ||
if err != nil { | ||
return err | ||
} | ||
defer rc.Close() | ||
|
||
// Create the destination file | ||
destPath := filepath.Join(destPath, f.Name) | ||
if f.FileInfo().IsDir() { | ||
// If the file entry in the ZIP archive is a directory, create the directory | ||
err = os.MkdirAll(destPath, f.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
// If the file entry in the ZIP archive is a file, create the file and write its content | ||
destFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
defer destFile.Close() | ||
|
||
_, err = io.Copy(destFile, rc) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |