-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.aardio
186 lines (163 loc) · 5.47 KB
/
main.aardio
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import win.ui;
import win.reg;
import fsys;
import fsys.file;
/*DSG{{*/
mainForm = win.form(text="MidGet";right=378;bottom=212;border="dialog frame";max=false;min=false)
mainForm.add(
ButtonEdit={cls="button";text="Edit";left=200;top=188;right=291;bottom=212;z=7};
ButtonSave={cls="button";text="Save";left=292;top=185;right=379;bottom=213;z=8};
Config={cls="edit";left=199;top=43;right=379;bottom=187;edge=1;multiline=1;readonly=1;z=5};
EDhelp={cls="edit";left=2;top=125;right=199;bottom=213;edge=1;hscroll=1;multiline=1;readonly=1;vscroll=1;z=9};
RegCheck={cls="button";text="CheckConfig";left=1;top=101;right=200;bottom=125;z=4};
RegReset={cls="button";text="ResetConfig";left=102;top=23;right=198;bottom=99;z=3};
RegSet={cls="button";text="SetConfig";left=2;top=23;right=102;bottom=99;z=2};
StaticConfigFile={cls="static";text="ConfigFile";left=258;top=23;right=316;bottom=47;transparent=1;z=6};
title={cls="static";text="GetMiddleSettings";left=3;top=1;right=377;bottom=21;align="center";transparent=1;z=1}
)
/*}}*/
function THROW_ERROR(id)
{
win.msgboxErr("Error id: "+id,"ERROR!");
return id;
}
function RenameReg(RegDicStr,oldName,newName)
{
var RegPath=win.reg(RegDicStr+"\"+oldName,true);
if(RegPath==null) return THROW_ERROR(-1);
if(win.reg(RegDicStr+"\"+newName,true)) return THROW_ERROR(-2);
return RegPath.renameKey(newName)
}
//"HKEY_CLASSES_ROOT\"+ProgidName+"\shell\open"
function SetMidGetReg(ProgidName)
{
RenameReg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell","open","TempOpen")
return RenameReg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell","MidGetOpen","open")
}
function SetOriginReg(ProgidName)
{
RenameReg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell","open","MidGetOpen")
return RenameReg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell","TempOpen","open")
}
function InitMidGetReg(ProgidName)
{
if(win.reg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell\TempOpen",true)!=null) return 1;
var RegPath=win.reg("HKEY_CLASSES_ROOT\"+ProgidName+"\shell\MidGetOpen\command");
return RegPath.setSzValue("",'"'+io._exepath+'" MIDGET '+ProgidName+' "%1"');
}
//win.msgbox(InitMidGetReg("YiYang.Suite.pptx"));
//win.msgbox(SetBackOriginReg("YiYang.Suite.pptx"));
function GetProgid(FileSuffix)
{
var UserChoicePath=win.reg("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+FileSuffix+"\UserChoice",true);
if(UserChoicePath==null) return THROW_ERROR(-1);
return UserChoicePath.queryValue("Progid")
}
function WorkWithConfig(ConfigFilePath,OperationName)
{
var cfg=fsys.file(ConfigFilePath,"r");
if(cfg==null) return THROW_ERROR(-11);
var FileSuffix;
while(1)
{
FileSuffix=cfg.read();
//win.msgbox(FileSuffix,"FileSuffix");
if(FileSuffix==null) break;
var Progid=GetProgid(FileSuffix);
//win.msgbox(Progid,"Progid");
if(Progid==-1) return THROW_ERROR(-21);
if(OperationName=="Set")
{
if(win.reg("HKEY_CLASSES_ROOT\"+Progid+"\shell\TempOpen",true)==null)
{
InitMidGetReg(Progid);
SetMidGetReg(Progid);
}
else
win.msgbox("Seems like "+Progid+" has already been set. ","ERROR")
}
else if(OperationName=="Check")
{
if(win.reg("HKEY_CLASSES_ROOT\"+Progid+"\shell\TempOpen",true)==null)
win.msgbox(Progid,"Set not okay. ");
}
else if(OperationName=="Reset")
{
SetOriginReg(Progid);
}
}
cfg.close();
}
var CFGfilePath=string.getenv("APPDATA")+"\MidGet\config.txt";
function Readcfg(ConfigFilePath)
{
var cfg=fsys.file(ConfigFilePath,"r");
if(cfg==null)
{
win.msgbox("No config File! Please Write! ","NoConfigFile");
return;
}
return cfg.read(-1);
}
function Writecfg(ConfigFilePath,text)
{
var cfg=fsys.file(ConfigFilePath,"w");
if(cfg==null) return THROW_ERROR(-11);
return cfg.write(text);
}
if(_ARGV[1]=="MIDGET")
{
var FilePath=_ARGV[3];
var Progid=_ARGV[2];
var blog;
fsys.createDir(string.getenv("APPDATA")+"\MidGet\collect");
blog=fsys.file(string.getenv("APPDATA")+"\MidGet\collect\blog.txt","a")
blog.write(FilePath+" ["+Progid+"] ("+tostring(time.now())+')\n');
blog.close();
SetOriginReg(Progid);
import process;
process.execute(FilePath,"open");
SetMidGetReg(Progid);
io.createDir(string.getenv("APPDATA")+"\MidGet\collect");
return fsys.copy(FilePath,string.getenv("APPDATA")+"\MidGet\collect");
}
else if(_ARGV[1]=="SET")
{
return WorkWithConfig(CFGfilePath,"Set");
}
else if(_ARGV[1]=="CHECK")
{
return WorkWithConfig(CFGfilePath,"Check");
}
else if(_ARGV[1]=="RESET")
{
return WorkWithConfig(CFGfilePath,"Reset");
}
mainForm.Config.text=Readcfg(CFGfilePath);
mainForm.RegSet.oncommand = function(id,event){
WorkWithConfig(CFGfilePath,"Set");
return;
}
mainForm.RegCheck.oncommand = function(id,event){
WorkWithConfig(CFGfilePath,"Check");
return;
}
mainForm.RegReset.oncommand = function(id,event){
WorkWithConfig(CFGfilePath,"Reset");
return;
}
mainForm.ButtonEdit.oncommand = function(id,event){
mainForm.Config.readonly=!mainForm.Config.readonly;
if(mainForm.ButtonEdit.text=="Edit")
mainForm.ButtonEdit.text="Lock";
else if(mainForm.ButtonEdit.text=="Lock")
mainForm.ButtonEdit.text="Edit";
}
mainForm.ButtonSave.oncommand = function(id,event){
return Writecfg(CFGfilePath,mainForm.Config.text);
}
mainForm.EDhelp.oncommand = function(id,event){
}
mainForm.EDhelp.text='A simple software to save files opened on the computer, mainly for students. \r\nUsage: \r\ntype the filetype(such as pptx ppt mp4) right and save. \r\nthe file will be store under:\r\n%APPDATA%\\MidGet\r\nSourceCode is on github:\r\nhttps://github.com/louiesun/MidGet\r\nIf useful, please star. '
mainForm.show();
return win.loopMessage();