forked from Jrohy/multi-v2ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.py
29 lines (25 loc) · 852 Bytes
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pickle
from profile import Profile
class Loader:
def __init__(self, path='/usr/local/multi-v2ray/multi-v2ray.dat'):
self.path = path
self.profile=None
self.load_profile()
def load_profile(self):
try:
if os.path.exists(self.path):
with open(self.path, 'rb') as reader:
self.profile = pickle.load(reader)
if os.path.getmtime(self.profile.path) != self.profile.modify_time:
raise ValueError
else:
raise FileNotFoundError
except Exception:
self.profile = Profile()
self.save_profile()
def save_profile(self):
with open(self.path, 'wb') as writer:
pickle.dump(self.profile, writer)