source: java/installer2/src/net/oni2/aeinstaller/backend/oni/PersistDat.java@ 846

Last change on this file since 846 was 624, checked in by alloc, 12 years ago

AEI2 0.84:

  • Actually *do* update packages
  • Uninstall backend for tools
File size: 1.7 KB
Line 
1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.io.RandomAccessFile;
7import java.util.HashSet;
8
9/**
10 * @author Christian Illy
11 */
12public class PersistDat {
13 private RandomAccessFile dat = null;
14
15 /**
16 * Open the given persist.dat
17 *
18 * @param dat
19 * Path to persist.dat
20 */
21 public PersistDat(File dat) {
22 try {
23 this.dat = new RandomAccessFile(dat, "rw");
24 } catch (FileNotFoundException e) {
25 e.printStackTrace();
26 }
27 }
28
29 /**
30 * @return Currently unlocked levels in persist.dat
31 */
32 public HashSet<Integer> getUnlockedLevels() {
33 HashSet<Integer> result = new HashSet<Integer>();
34 if (dat != null) {
35 try {
36 dat.seek(8);
37 for (int i = 0; i < 32; i++) {
38 int val = dat.read();
39 for (int j = 0; j < 8; j++) {
40 if ((val & (1 << j)) > 0) {
41 result.add(i * 8 + j);
42 }
43 }
44 }
45 } catch (IOException e) {
46 // TODO Auto-generated catch block
47 e.printStackTrace();
48 }
49 }
50 return result;
51 }
52
53 /**
54 * @param unlock
55 * Levels to be unlocked in persist.dat
56 */
57 public void setUnlockedLevels(HashSet<Integer> unlock) {
58 if (dat != null) {
59 if (unlock != null) {
60 try {
61 dat.seek(8);
62 for (int i = 0; i < 32; i++) {
63 int val = 0;
64 for (int j = 0; j < 8; j++) {
65 if (unlock.contains(i * 8 + j))
66 val |= 1 << j;
67 }
68 dat.write(val);
69 }
70 } catch (IOException e) {
71 // TODO Auto-generated catch block
72 e.printStackTrace();
73 }
74 }
75 }
76 }
77
78 /**
79 * Close file
80 */
81 public void close() {
82 if (dat != null) {
83 try {
84 dat.close();
85 } catch (IOException e) {
86 e.printStackTrace();
87 }
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.