<commit_before>//
//  Config.swift
//  trailer
//
//  Created by <NAME> on 21/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Config {
	var server = URL(string: "https://api.github.com/graphql")!

	var pageSize = 50

	var monochrome = false

	let versionMajor = 1
	let versionMinor = 1
	let versionPatch = 1
	var versionString: String {
		return [versionMajor, versionMinor, versionPatch].map { String($0) }.joined(separator: ".")
	}

	func isNewer(_ version: String) -> Bool {
		var local = [0, 0, 0]
		let components = version.split(separator: ".")
		for i in 0 ..< components.count {
			if let n = Int(String(components[i])) {
				local[i] = n
			}
		}
		
		if versionMajor < local[0] {
			return true
		} else if versionMajor > local[0] {
			return false
		}

		if versionMinor < local[1] {
			return true
		} else if versionMinor > local[1] {
			return false
		}

		if versionPatch < local[2] {
			return true
		} else if versionPatch > local[2] {
			return false
		}

		return false
	}

	var httpHeaders: [String: String] {
		#if DEBUG
			let variant = "Development"
		#else
			let variant = "Release"
		#endif

		#if os(OSX)
			let OS = "macOS"
		#elseif os(Linux)
			let OS = "Linux"
        #elseif os(Windows)
            let OS = "Linux"
		#endif

		return [
			"Authorization": "bearer \(token)",
			"User-Agent": "Trailer-CLI-v\(versionString)-\(OS)-\(variant)"
		]
	}

	var myUser: User? {
		didSet {
			if let u = myUser {
				myLogin = "@\(u.login)"
			} else {
				myLogin = ""
			}
		}
	}

	var myLogin: String = ""

	var token: String {
		get {
			if let d = try? Data(contentsOf: saveLocation.appendingPathComponent("token")) {
				return String(data:d, encoding: .utf8) ?? ""
			}
			return ""
		}
		set {
			try! newValue.data(using: .utf8)?.write(to: saveLocation.appendingPathComponent("token"))
		}
	}

	private func store(date: Date?, name: String) {
		var dateTickString: String?<commit_msg>Change token file permissions to 0600 (#9)<commit_after>//
//  Config.swift
//  trailer
//
//  Created by <NAME> on 21/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Config {
	var server = URL(string: "https://api.github.com/graphql")!

	var pageSize = 50

	var monochrome = false

	let versionMajor = 1
	let versionMinor = 1
	let versionPatch = 1
	var versionString: String {
		return [versionMajor, versionMinor, versionPatch].map { String($0) }.joined(separator: ".")
	}

	func isNewer(_ version: String) -> Bool {
		var local = [0, 0, 0]
		let components = version.split(separator: ".")
		for i in 0 ..< components.count {
			if let n = Int(String(components[i])) {
				local[i] = n
			}
		}
		
		if versionMajor < local[0] {
			return true
		} else if versionMajor > local[0] {
			return false
		}

		if versionMinor < local[1] {
			return true
		} else if versionMinor > local[1] {
			return false
		}

		if versionPatch < local[2] {
			return true
		} else if versionPatch > local[2] {
			return false
		}

		return false
	}

	var httpHeaders: [String: String] {
		#if DEBUG
			let variant = "Development"
		#else
			let variant = "Release"
		#endif

		#if os(OSX)
			let OS = "macOS"
		#elseif os(Linux)
			let OS = "Linux"
        #elseif os(Windows)
            let OS = "Linux"
		#endif

		return [
			"Authorization": "bearer \(token)",
			"User-Agent": "Trailer-CLI-v\(versionString)-\(OS)-\(variant)"
		]
	}

	var myUser: User? {
		didSet {
			if let u = myUser {
				myLogin = "@\(u.login)"
			} else {
				myLogin = ""
			}
		}
	}

	var myLogin: String = ""

	var token: String {
		get {
			if let d = try? Data(contentsOf: saveLocation.appendingPathComponent("token")) {
				return String(data:d, encoding: .utf8) ?? ""
			}
			return ""
		}
		set {
			let tokenFileURL = saveLocation.appendingPathComponent("token")
			try! newValue.data(using: .utf8)?.write(to: tokenFileURL)
			try! FileManager.default.setAttributes([.posixPermissions: NSNumber(0o600)], ofItemAtPath: tokenFileURL.path)
		}
	}

	private func store(date: Date?, name: String) {
		var dateTickString: String?
{'fraction_non_alphanumeric': 0.14163614163614163, 'fraction_numerical': 0.01684981684981685, 'mean_word_length': 2.8424015009380863, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506467', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1429, 'n_words': 385}