OSDN Git Service

ee557147e467bd08d9fa0a08ca8739fcdf583038
[coroid/inqubus.git] / frontend / src / saccubus / net / CookieWinFirefox4.java
1 package saccubus.net;
2
3 import java.io.IOException;
4
5 /**
6  *
7  * @author yuki
8  */
9 public class CookieWinFirefox4 extends Cookie {
10
11     /// <summary>
12     /// Firefox4, 5 から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
13     /// </summary>
14     /// <returns>user_session</returns>
15     @Override
16     public String getUserSessionString() throws IOException {
17         String user_session = "";
18         try {
19             String app_dir = System.getenv("APPDATA");
20             if (app_dir == null || app_dir.isEmpty()) {
21                 return "";
22             }
23             String[] userLists = Path.GetFiles(app_dir + "\\Mozilla\\Firefox\\Profiles\\");
24             for (String user_dir : userLists) {
25                 String sqlist_filename = user_dir + "\\cookies.sqlite";
26                 if (Path.isFile(sqlist_filename)) {
27                     String dataStr = Path.ReadAllText(sqlist_filename, "US-ASCII");
28                     user_session = CutUserSession(dataStr, sqlist_filename);
29                     if (!user_session.isEmpty()) {
30                         return user_session;
31                     }
32                     // else continue
33                 }
34             }
35             return "";  // not found
36         } catch (Exception e) {
37             e.printStackTrace();
38             return "";
39         }
40
41     }
42 }