Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build/curd-windows-build.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Setup]
AppName=Curd Installer
AppVersion=1.0.8
AppVersion=1.2.0
DefaultDirName={userappdata}\Curd
PrivilegesRequired=lowest
AllowNoIcons=yes
Expand Down
22 changes: 15 additions & 7 deletions cmd/curd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,32 @@ func main() {

flag.Parse()

currentVersion := internal.ResolveCurrentVersion(version)

// Check version before screen clearing
if *versionFlag {
internal.RestoreScreen()
if version == "" {
version = "1.2.0"
if currentVersion == "" {
if version == "" {
currentVersion = "1.2.0"
} else {
currentVersion = version
}
}
fmt.Printf("Curd version: %s\n", version)
fmt.Printf("Curd version: %s\n", currentVersion)
os.Exit(0)
}

anime.Ep.ContinueLast = *continueLast

if *updateScript {
repo := "wraient/curd"
fileName := "curd"

if err := internal.UpdateCurd(repo, fileName); err != nil {
updateMessage, err := internal.UpdateCurd(repo)
if err != nil {
internal.CurdOut(fmt.Sprintf("Error updating executable: %v\n", err))
internal.ExitCurd(err)
} else {
internal.CurdOut("Program Updated!")
internal.CurdOut(updateMessage)
internal.ExitCurd(nil)
}
}
Expand Down Expand Up @@ -141,6 +146,9 @@ func main() {
return
}

internal.NotifyAboutCachedUpdate(currentVersion, userCurdConfig.StoragePath)
internal.StartBackgroundReleaseCheck(currentVersion, userCurdConfig.StoragePath)

// Set SubOrDub based on the flags
if *subFlag {
userCurdConfig.SubOrDub = "sub"
Expand Down
101 changes: 0 additions & 101 deletions internal/curd.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,107 +508,6 @@ updateOptionLoop:
}
}

func UpdateCurd(repo, fileName string) error {
// Get the path of the currently running executable
executablePath, err := os.Executable()
if err != nil {
return fmt.Errorf("unable to find current executable: %v", err)
}

// Determine the correct binary name based on OS and architecture
var binaryName string
switch runtime.GOOS {
case "windows":
if runtime.GOARCH == "arm64" {
binaryName = "curd-windows-arm64.exe"
} else {
binaryName = "curd-windows-x86_64.exe"
}
case "darwin": // macOS
switch runtime.GOARCH {
case "amd64":
binaryName = "curd-macos-x86_64"
case "arm64":
binaryName = "curd-macos-arm64"
default:
binaryName = "curd-macos-universal"
}
case "linux":
switch runtime.GOARCH {
case "amd64":
binaryName = "curd-linux-x86_64"
case "arm64":
binaryName = "curd-linux-arm64"
default:
return fmt.Errorf("unsupported Linux architecture: %s", runtime.GOARCH)
}
default:
return fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
}

// GitHub release URL for curd
url := fmt.Sprintf("https://github.com/%s/releases/latest/download/%s", repo, binaryName)

// Temporary path for the downloaded curd executable
tmpPath := executablePath + ".tmp"

// Download the curd executable
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to download file: %v", err)
}
defer resp.Body.Close()

// Check if the download was successful
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download file: received status code %d", resp.StatusCode)
}

// Create a new temporary file
out, err := os.Create(tmpPath)
if err != nil {
return fmt.Errorf("failed to create temporary file: %v", err)
}
defer out.Close()

// Set file permissions
if err := out.Chmod(0755); err != nil {
return fmt.Errorf("failed to set file permissions: %v", err)
}

// Copy the downloaded content to the temporary file
if _, err := io.Copy(out, resp.Body); err != nil {
return fmt.Errorf("failed to write to temporary file: %v", err)
}

// Close the file before renaming
out.Close()

// Replace the old executable with the new one
if runtime.GOOS == "windows" {
// On Windows, we need to rename the old file first
oldPath := executablePath + ".old"
err = os.Rename(executablePath, oldPath)
if err != nil {
return fmt.Errorf("failed to rename old executable: %v", err)
}
err = os.Rename(tmpPath, executablePath)
if err != nil {
// Try to restore the old executable if the rename fails
os.Rename(oldPath, executablePath)
return fmt.Errorf("failed to rename new executable: %v", err)
}
os.Remove(oldPath)
} else {
// On Unix systems, we can directly rename
if err := os.Rename(tmpPath, executablePath); err != nil {
return fmt.Errorf("failed to replace executable: %v", err)
}
}

return nil
}

func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime) SelectionOption {
var query string
// Remove the redeclared variable declaration since animeOptions is already declared above
Expand Down
Loading
Loading