Skip to content

Commit

Permalink
fix free trial login and add download limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
marzent committed Mar 11, 2022
1 parent c6e4508 commit 866e60c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Binary file not shown.
9 changes: 6 additions & 3 deletions XIV on Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ Gw
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="updateRetina:" target="GIg-v3-M8h" id="5Km-ai-97d"/>
<action selector="saveState:" target="GIg-v3-M8h" id="LkF-Z8-nFy"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YDL-Cb-Q7P">
Expand Down Expand Up @@ -1700,7 +1700,7 @@ Gw
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="updateRetina:" target="GIg-v3-M8h" id="CqN-DD-ioK"/>
<action selector="updateMaxDownload:" target="GIg-v3-M8h" id="hwO-qI-k1T"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ts9-EP-Wqa">
Expand Down Expand Up @@ -1732,10 +1732,13 @@ Gw
<outlet property="esync" destination="5oa-uD-168" id="ZSN-V1-stL"/>
<outlet property="fps" destination="Ogm-ZO-E2w" id="OPW-hm-cEk"/>
<outlet property="frametimes" destination="DSc-kA-8q1" id="NQ8-Yx-XTB"/>
<outlet property="freeTrial" destination="Jmh-Hz-ux7" id="iOI-mm-OQz"/>
<outlet property="gpuload" destination="4Fq-Sz-2ZL" id="kpD-xR-1mP"/>
<outlet property="keepPatches" destination="Jmh-Hz-ux7" id="f2H-IH-dMq"/>
<outlet property="keepPatches" destination="7H0-sz-e1J" id="YlN-6O-4uM"/>
<outlet property="language" destination="tOj-q2-gaD" id="YA2-qM-B6g"/>
<outlet property="license" destination="eWT-Ny-Sac" id="MFZ-zh-TaL"/>
<outlet property="maxDownload" destination="eVo-GZ-iwf" id="FQD-t0-4Zm"/>
<outlet property="maxDownloadField" destination="zft-mL-IyQ" id="dkM-y6-tfo"/>
<outlet property="maxFPS" destination="0PH-1i-0UA" id="3Y1-La-IoX"/>
<outlet property="maxFPSField" destination="uQd-FB-xmH" id="pew-u4-IUq"/>
<outlet property="memory" destination="HvH-pN-nVO" id="69Q-ki-iMz"/>
Expand Down
2 changes: 1 addition & 1 deletion XIV on Mac/Launcher/FFXIVLoginServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct FFXIVLogin {
let ticket = Steam.ticket

var loginURL: URL {
let base = "https://ffxiv-login.square-enix.com/oauth/ffxivarr/login/top?lng=en&rgn=\(settings.region.rawValue)&isft=0&cssmode=1&isnew=1&launchver=3"
let base = "https://ffxiv-login.square-enix.com/oauth/ffxivarr/login/top?lng=en&rgn=\(settings.region.rawValue)&isft=\(settings.freeTrial ? "1" : "0")&cssmode=1&isnew=1&launchver=3"
guard let ticket = ticket, settings.platform == .steam else {
return URL(string: base)!
}
Expand Down
14 changes: 12 additions & 2 deletions XIV on Mac/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension HTTPClient {
var now: Double
}

static func fetchFile(url: URL, destinationUrl: URL? = nil, headers: OrderedDictionary<String, String>? = nil, proxy: String? = nil, maxSpeed: Int = 0, progressCallback: ((Int64, Int64, Int64) -> Void)? = nil) throws {
static func fetchFile(url: URL, destinationUrl: URL? = nil, headers: OrderedDictionary<String, String>? = nil, proxy: String? = nil, progressCallback: ((Int64, Int64, Int64) -> Void)? = nil) throws {
let destURL = destinationUrl ?? Util.cache.appendingPathComponent(url.lastPathComponent)
if FileManager().fileExists(atPath: destURL.path) {
print("File already exists [\(destURL.path)]")
Expand All @@ -61,7 +61,7 @@ extension HTTPClient {
try curl.set(option: CURLOPT_FOLLOWLOCATION, true)
try curl.set(option: CURLOPT_LOW_SPEED_TIME, 120)
try curl.set(option: CURLOPT_LOW_SPEED_LIMIT, 30)
try curl.set(option: CURLOPT_MAX_RECV_SPEED_LARGE, maxSpeed)
try curl.set(option: CURLOPT_MAX_RECV_SPEED_LARGE, Int(HTTPClient.maxSpeed * 1000000))
if let proxy = proxy {
try curl.set(option: CURLOPT_PROXY, proxy)
}
Expand Down Expand Up @@ -125,4 +125,14 @@ extension HTTPClient {
}
}

private static let maxSpeedKey = "MaxDownloadSpeed"
static var maxSpeed: Double {
get {
return Util.getSetting(settingKey: maxSpeedKey, defaultValue: 0.0)
}
set(newDelay) {
UserDefaults.standard.set(newDelay, forKey: maxSpeedKey)
}
}

}
20 changes: 20 additions & 0 deletions XIV on Mac/SettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
//

import Cocoa
import SeeURL

class SettingsController: NSViewController {
@IBOutlet private var language: NSPopUpButton!
@IBOutlet private var license: NSPopUpButton!
@IBOutlet private var freeTrial: NSButton!

@IBOutlet private var maxDownload: NSButton!
@IBOutlet private var maxDownloadField: NSTextField!
@IBOutlet private var keepPatches: NSButton!

@IBOutlet private var devinfo: NSButton!
Expand Down Expand Up @@ -85,6 +90,12 @@ class SettingsController: NSViewController {
saveState()
}

@IBAction func updateMaxDownload(_ sender: Any) {
let button = sender as! NSButton
maxDownloadField.isEnabled = (button.state == NSControl.StateValue.on) ? true : false
saveState()
}

@IBAction func updateRetina(_ sender: NSButton) {
Wine.retina = (sender.state == NSControl.StateValue.on)
}
Expand Down Expand Up @@ -112,6 +123,12 @@ class SettingsController: NSViewController {

language.selectItem(at: Int(FFXIVSettings.language.rawValue))
license.selectItem(at: Int(FFXIVSettings.platform.rawValue))
freeTrial.state = FFXIVSettings.freeTrial ? NSControl.StateValue.on : NSControl.StateValue.off

let limitedDown = HTTPClient.maxSpeed > 0
maxDownload.state = limitedDown ? NSControl.StateValue.on : NSControl.StateValue.off
maxDownloadField.isEnabled = limitedDown
maxDownloadField.stringValue = String(HTTPClient.maxSpeed)
keepPatches.state = Patch.keep ? NSControl.StateValue.on : NSControl.StateValue.off
}

Expand All @@ -136,6 +153,9 @@ class SettingsController: NSViewController {

FFXIVSettings.language = FFXIVLanguage(rawValue: UInt32(language.indexOfSelectedItem)) ?? .english
FFXIVSettings.platform = FFXIVPlatform(rawValue: UInt32(license.indexOfSelectedItem)) ?? .mac
FFXIVSettings.freeTrial = (freeTrial.state == NSControl.StateValue.on) ? true : false

HTTPClient.maxSpeed = maxDownloadField.isEnabled ? Double(maxDownloadField.stringValue) ?? 0.0 : 0.0
Patch.keep = (keepPatches.state == NSControl.StateValue.on) ? true : false
}

Expand Down

0 comments on commit 866e60c

Please sign in to comment.