diff --git a/README.md b/README.md index 89d9e32..f1ece0a 100755 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ these steps to setup the project directory. ``` ./gradlew idea - ./gradlew genIntellijRuns ``` 2. Open the project folder with Intellij, and import the Gradle project when prompted. @@ -83,6 +82,20 @@ followed by *Other* for the Application type. 4. Download the json credentials by clicking the following icon for your project: ![Download json](download_json.png) +5. Run the YouTube Chat jar from a terminal to obtain authorization credentials, +pasting the client ID JSON when prompted: + +``` +java -jar ytchat-1.0.3.jar login +``` + +If you want to clear your credentials or sign in as a different user, run logout: + +``` +java -jar ytchat-1.0.3.jar logout +``` + +Credentials are be saved to ~/.oauth-credentials. ## Configuration diff --git a/dependencies.txt b/dependencies.txt index 318df16..4446bb4 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -28,6 +28,9 @@ task saveDependencies << { } jar { + manifest { + attributes 'Main-Class': 'com.google.youtube.gaming.chat.Main' + } from configurations.embed.collect { exclude 'META-INF/LICENSE*' exclude 'META-INF/NOTICE*' diff --git a/setup.gradle b/setup.gradle index 04ac210..a0f5d30 100644 --- a/setup.gradle +++ b/setup.gradle @@ -46,7 +46,7 @@ task updateMdk(dependsOn: 'stageMdk') { String text = buildGradle.getText('UTF-8') text = text.replaceAll('com.yourname.modid', 'com.google.youtube.ytchat') text = text.replaceAll('modid', 'ytchat') - text = text.replaceAll('1\\.0', '1.0.2') + text = text.replaceAll('1\\.0', '1.0.3') text = text.replace('repositories {', 'repositories {\n mavenCentral()'); text = text.replaceFirst(/\ndependencies\s?\{[^\}]+\}/, dependencyText); buildGradle.write(text, 'UTF-8') diff --git a/src/main/java/com/google/youtube/gaming/chat/Auth.java b/src/main/java/com/google/youtube/gaming/chat/Auth.java index d4d2140..4b68b90 100755 --- a/src/main/java/com/google/youtube/gaming/chat/Auth.java +++ b/src/main/java/com/google/youtube/gaming/chat/Auth.java @@ -31,10 +31,7 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Collection; -import org.apache.commons.io.FileUtils; /** * Contains methods for authorizing a user and caching credentials. @@ -84,10 +81,24 @@ public static Credential authorize( public static void clearCredentials() throws IOException { File directory = new File(getCredentialsDirectory()); if (directory.exists()) { - FileUtils.deleteDirectory(directory); + deleteDirectory(directory); } } + private static boolean deleteDirectory(File path) { + if (path.exists()) { + File[] files = path.listFiles(); + for(int i=0; i < files.length; i++) { + if(files[i].isDirectory()) { + deleteDirectory(files[i]); + } else { + files[i].delete(); + } + } + } + return path.delete(); + } + private static String getCredentialsDirectory() { return System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY; } diff --git a/src/main/java/com/google/youtube/gaming/chat/Main.java b/src/main/java/com/google/youtube/gaming/chat/Main.java new file mode 100644 index 0000000..2bd1839 --- /dev/null +++ b/src/main/java/com/google/youtube/gaming/chat/Main.java @@ -0,0 +1,54 @@ +/** + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.google.youtube.gaming.chat; + +import com.google.api.services.youtube.YouTubeScopes; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + if (args.length == 0) { + showUsage(); + return; + } + + switch (args[0]) { + case "login": + System.out.print("Paste the client ID JSON from the Google API console:"); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String clientSecret = br.readLine(); + List scopes = new ArrayList(); + scopes.add(YouTubeScopes.YOUTUBE_FORCE_SSL); + scopes.add(YouTubeScopes.YOUTUBE); + Auth.authorize(scopes, clientSecret, YouTubeChat.MODID); + break; + case "logout": + Auth.clearCredentials(); + break; + default: + showUsage(); + } + } + + private static void showUsage() { + System.err.println("Supported arguments: login | logout"); + } +} diff --git a/src/main/java/com/google/youtube/gaming/chat/YouTubeChat.java b/src/main/java/com/google/youtube/gaming/chat/YouTubeChat.java index 5850d3f..bdfceb5 100755 --- a/src/main/java/com/google/youtube/gaming/chat/YouTubeChat.java +++ b/src/main/java/com/google/youtube/gaming/chat/YouTubeChat.java @@ -30,7 +30,7 @@ public class YouTubeChat { public static final String MODID = "ytchat"; public static final String APPNAME = "YouTube Chat"; - public static final String VERSION = "1.0.2"; + public static final String VERSION = "1.0.3"; public static final String GUI_FACTORY = "com.google.youtube.gaming.chat.YouTubeConfigurationGuiFactory";