+++ /dev/null
-/**
- * Inspired from Nicorank by rankingloid 2008 - 2009
- */
-package saccubus.net;
-
-import java.util.Arrays;
-
-/**
-/**
- * <p>
- * タイトル: さきゅばす
- * </p>
- *
- * <p>
- * 説明: ニコニコ動画の動画をコメントつきで保存
- * </p>
- *
- * @version 1.22r3e
- * @author orz
- *
- */
-public class BrowserInfo {
- /*
- * [DllImport("wininet.dll")]
- * private extern static bool InternetGetCookie(string url, string name, StringBuilder data, ref uint size);
- *
- * shuold use NLink.win32
- */
-
-
- /** <p>
- * Chromium から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
- * </p>
- * @return user_session
- */
- private String GetUserSesionChromium() {
- String user_session = "";
- String cookie_file = "";
- String chromium = "\\Chromium\\User Data\\Default\\Cookies";
- try {
- String local_Appdir = System.getenv("LOCALAPPDATA");
- if (local_Appdir != null && !local_Appdir.isEmpty()) {
- // Win7 32bit
- cookie_file = local_Appdir + chromium;
- if (Path.isFile(cookie_file)) {
- String dataStr = Path.ReadAllText(cookie_file, "UTF-8");
- user_session = CutUserSession(dataStr, cookie_file);
- return user_session;
- }
- }
- String profile_dir = System.getenv("USERPROFILE");
- if (profile_dir != null && !profile_dir.isEmpty()) {
- // XP 32bit
- cookie_file = profile_dir
- + "\\Local Settings\\Application Data" + chromium;
- if (Path.isFile(cookie_file)) {
- String dataStr = Path.ReadAllText(cookie_file, "UTF-8");
- user_session = CutUserSession(dataStr, cookie_file);
- return user_session;
- }
- }
- return user_session;
- } catch (Exception e) {
- e.printStackTrace();
- return user_session;
- }
- }
-
-}
public enum BrowserType {
- NONE, MSIE, IE6, FIREFOX, CHROME,
- OPERA, CHROMIUM, OTHER
+ MSIE, FIREFOX, CHROME, CHROMIUM, OPERA, OTHER
}
- public static Cookie create(BrowserType type) {
+ public static Cookie create(BrowserType type, String dir) {
switch (type) {
- case CHROME:
- return new CookieWinCrome();
- case FIREFOX:
- return new CookieWinFirefox4();
case MSIE:
return new CookieWinMsIe();
+ case FIREFOX:
+ return new CookieWinFirefox4();
+ case CHROME:
+ return new CookieWinCrome();
+ case CHROMIUM:
+ return new CookieWinChromium();
+ case OPERA:
+ return new CookieWinOpera();
default:
- throw new UnsupportedOperationException();
+ final File f = new File(dir);
+ return new CookieDefault(f);
}
}
--- /dev/null
+package saccubus.net;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Windows Chromium用.
+ * @author yuki
+ */
+public class CookieWinChromium extends Cookie {
+
+ private static final String CHROMIUM_PATH = "\\Chromium\\User Data\\Default\\Cookies";
+
+ @Override
+ public String getUserSessionString() throws IOException {
+ final String localAppData = System.getenv("LOCALAPPDATA");
+ if (StringUtils.isNotEmpty(localAppData)) {
+ // Win7 32bit
+ final File cookieFile = new File(localAppData + CHROMIUM_PATH);
+ if (cookieFile.isFile()) {
+ return getUserSession("UTF-8", cookieFile);
+ }
+ }
+
+ final String userProfile = System.getenv("USERPROFILE");
+ if (StringUtils.isNotEmpty(userProfile)) {
+ // XP 32bit
+ final File cookieFile = new File(userProfile + "\\Local Settings\\Application Data" + CHROMIUM_PATH);
+ if (cookieFile.isFile()) {
+ return getUserSession("UTF-8", cookieFile);
+ }
+ }
+
+ throw new IOException();
+
+ }
+}
import java.io.File;
import java.io.IOException;
-import java.nio.file.Path;
import org.apache.commons.lang.StringUtils;
/**