1 | ' Gambas module file |
---|
2 | PUBLIC sLockFile AS String = "/tmp/rpminstall." & System.User.Id ' lock file path |
---|
3 | PUBLIC hLockFile AS File ' handler for lock file |
---|
4 | PUBLIC sArch AS String ' hold arch string |
---|
5 | |
---|
6 | PUBLIC SUB Main() |
---|
7 | |
---|
8 | DIM i AS Integer |
---|
9 | DIM sOutput AS String |
---|
10 | |
---|
11 | ' if lock file already exist and other instance are running, |
---|
12 | ' then add arguments to lock file and exit. |
---|
13 | SHELL "pgrep -f -U " & User.ID & " " & Application.Args[0] TO sOutput |
---|
14 | IF Exist(sLockFile) = TRUE AND IF Split(Trim$(sOutput), "\n").Count > 1 THEN |
---|
15 | hLockFile = OPEN sLockFile FOR APPEND |
---|
16 | FOR i = 1 TO Application.Args.Count - 1 |
---|
17 | PRINT #hLockFile, Application.Args[i] |
---|
18 | NEXT |
---|
19 | hLockFile.Close() |
---|
20 | PRINT ("Lock file exists. Seems other rpminstall is running.") |
---|
21 | ELSE |
---|
22 | ' create lock file (size = 0) |
---|
23 | hLockFile = OPEN sLockFile FOR CREATE |
---|
24 | hLockFile.Close() |
---|
25 | |
---|
26 | ' get current system arch type using rpm command. |
---|
27 | EXEC ["rpm", "--eval", "%{_arch}"] TO sArch |
---|
28 | sArch = Split(sArch, "\n")[0] |
---|
29 | IF sArch = "i386" THEN |
---|
30 | sArch = "i?86" |
---|
31 | ELSE IF sArch = "x86_64" THEN ' i?86.rpm should be installable on x86_64 <BTS:VineLinux:0725> |
---|
32 | sArch = "*86*" |
---|
33 | ENDIF |
---|
34 | |
---|
35 | ' store arguments to listview |
---|
36 | IF Application.Args.Count > 1 THEN |
---|
37 | FOR i = 1 TO Application.Args.Count - 1 |
---|
38 | AddRPMtolvwMain(Application.Args[i]) |
---|
39 | NEXT |
---|
40 | ENDIF |
---|
41 | FMain.Show() |
---|
42 | ENDIF |
---|
43 | |
---|
44 | END |
---|
45 | |
---|
46 | PUBLIC SUB AddRPMtolvwMain(sFile AS String) |
---|
47 | |
---|
48 | DIM s2ndExt AS String |
---|
49 | |
---|
50 | ' ignore not suitable files and store them to listview (use filename as key) |
---|
51 | ' check extention is "rpm" |
---|
52 | IF File.Ext(sFile) = "rpm" THEN |
---|
53 | ' check sArch or "noarch" or "src" for 2nd(?) extention |
---|
54 | s2ndExt = File.Ext(File.BaseName(sFile)) |
---|
55 | IF s2ndExt LIKE sArch OR IF s2ndExt = "noarch" OR IF s2ndExt = "src" THEN |
---|
56 | ' check duplicate |
---|
57 | IF FMain.lvwMain.Exist(File.Name(sFile)) = FALSE THEN |
---|
58 | FMain.lvwMain.Add(File.Name(sFile), sFile, Picture.Load("rpm.png")) |
---|
59 | ENDIF |
---|
60 | ENDIF |
---|
61 | ENDIF |
---|
62 | |
---|
63 | END |
---|