-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmain.au3
More file actions
449 lines (379 loc) · 14.9 KB
/
main.au3
File metadata and controls
449 lines (379 loc) · 14.9 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/MO
#Region license
; -----------------------------------------------------------------------------
; Simple IP Config is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; Simple IP Config is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Simple IP Config. If not, see <http://www.gnu.org/licenses/>.
; -----------------------------------------------------------------------------
#EndRegion license
;==============================================================================
; Filename: main.au3
; Description: - call functions to read profiles, get adapters list, create the gui
; - while loop to keep program running
; - check for instance already running
;==============================================================================
;==============================================================================
;
; Name: Simple IP Config
;
; Description: Simple IP Config is a program for Windows to easily change
; various network settings in a format similar to the
; built-in Windows configuration.
;
; Required OS: Windows XP, Windows Vista, Windows 7, Windows 8, Window 8.1, Windows 10
;
; Author: Kurtis Liggett
;
;==============================================================================
#RequireAdmin
#NoTrayIcon ;prevent double icon when checking for already running instance
#include <WindowsConstants.au3>
#include <APIConstants.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <GUIImageList.au3>
#include <GuiListView.au3>
#include <GuiIPAddress.au3>
#include <GuiMenu.au3>
#include <Misc.au3>
#include <Color.au3>
#include <GUIEdit.au3>
#include <GuiComboBox.au3>
#include <GuiRichEdit.au3>
#include <Array.au3>
#include <Date.au3>
#include <Inet.au3>
#include <File.au3>
#include "libraries\GetInstalledPath.au3"
#include "libraries\AutoItObject.au3"
#include "libraries\oLinkedList.au3"
_AutoItObject_StartUp()
#Region options
Opt("TrayIconHide", 0)
Opt("GUIOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Opt("MouseCoordMode", 2)
Opt("GUIResizeMode", $GUI_DOCKALL)
Opt("WinSearchChildren", 1)
Opt("GUICloseOnESC", 0)
;~ Opt("MustDeclareVars", 1)
TraySetClick(16)
#EndRegion options
; autoit wrapper options
#AutoIt3Wrapper_Res_HiDpi=y
#AutoIt3Wrapper_UseX64=N
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_OutFile=Simple IP Config 2.9.8-b1.exe
#AutoIt3Wrapper_Res_Fileversion=2.9.8
#AutoIt3Wrapper_Res_Description=Simple IP Config
#Region Global Variables
Global $options
Global $profiles
Global $adapters
#include <GUIConstantsEx.au3>
; Global constants, for code readability
Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20
Global $screenshot = 1
Global $sProfileName
;set profile name based on installation and script dir
_setProfilesIniLocation()
;GUI stuff
Global $winName = "Simple IP Config"
Global $winVersion = "2.9.8-b1"
Global $winDate = "5/15/2023"
Global $hgui
Global $guiWidth = 600
Global $guiHeight = 675
Global $footerHeight = 16
Global $tbarHeight = 0
Global $dscale = 1
Global $iDPI = 0
Global $infoWidth = 395
Global $guiMinWidth, $guiMinHeight, $guiMaxWidth, $guiMaxHeight, $guiRightWidth
Global $headingHeight = 20
Global $menuHeight, $captionHeight
Global $MinToTray, $RestoreItem, $aboutitem, $exititem, $exititemtray
Global $aAccelKeys[12][2]
;GUI Fonts
Global $MyGlobalFontName = "Arial"
Global $MyGlobalFontSize = 9.5
Global $MYGlobalFontSizeLarge = 11
Global $MyGlobalFontColor = 0x000000
Global $MyGlobalFontBKColor = $GUI_BKCOLOR_TRANSPARENT
Global $MyGlobalFontHeight = 0
;Statusbar
Global $statusbarHeight = 20
Global $statusChild, $RestartChild
Global $statustext, $statuserror, $sStatusMessage
Global $wgraphic, $showWarning, $statusPopupEdit
;Menu Items
Global $filemenu, $applyitem, $renameitem, $newitem, $saveitem, $deleteitem, $clearitem, $createLinkItem, $profilesOpenItem, $profilesImportItem, $profilesExportItem, $exititem, $netConnItem
Global $viewmenu, $refreshitem, $send2trayitem, $blacklistitem, $appearancemenu, $lightmodeitem, $darkmodeitem
Global $toolsmenu, $pullitem, $disableitem, $releaseitem, $renewitem, $cycleitem, $settingsitem
Global $helpmenu, $helpitem, $changelogitem, $checkUpdatesItem, $debugmenuitem, $infoitem
Global $lvcon_rename, $lvcon_delete, $lvcon_arrAz, $lvcon_arrZa, $lvcreateLinkItem
;Settings window
Global $ck_mintoTray, $ck_startinTray, $ck_saveAdapter, $ck_autoUpdate, $cmb_langSelect
Global $timerstart, $timervalue
Global $movetosubnet
Global $mdblTimerInit = 0, $mdblTimerDiff = 1000, $mdblClick = 0, $mDblClickTime = 500
Global $dragging = False, $dragitem = 0, $contextSelect = 0
Global $prevWinPos, $winPosTimer, $writePos
Global $OpenFileFlag, $ImportFileFlag, $ExportFileFlag
Global $buttonCopyOffset, $buttonPasteOffset, $buttonRefreshOffset, $buttonApplyOffset, $IpAddressOffset
; CONTROLS
Global $combo_adapters, $combo_dummy, $selected_adapter, $lDescription, $lMac
Global $list_profiles, $input_filter, $filter_dummy, $dummyUp, $dummyDown
Global $lv_oldName, $lv_newName, $lv_editIndex, $lv_doneEditing, $lv_newItem, $lv_startEditing, $lv_editing, $lv_aboutEditing, $lvTabKey
Global $radio_IpAuto, $radio_IpMan, $ip_Ip, $ip_Subnet, $ip_Gateway, $dummyTab
Global $radio_DnsAuto, $radio_DnsMan, $ip_DnsPri, $ip_DnsAlt
Global $label_CurrentIp, $label_CurrentSubnet, $label_CurrentGateway
Global $label_CurrentDnsPri, $label_CurrentDnsAlt
Global $label_CurrentDhcp, $label_CurrentAdapterState
Global $link, $computerName, $domainName
Global $blacklistLV
Global $button_New, $button_Save, $button_Delete, $menuLineBottom, $menuLineRight, $menuLineSep, $memo, $memoBackground, $memoLabel, $memoLabelBackground, $memoCtrls[6]
Global $headingSelect, $headingProfiles, $headingIP, $headingCurrent
Global $label_CurrIp, $label_CurrSubnet, $label_CurrGateway, $label_CurrDnsPri, $label_CurrDnsAlt, $label_CurrDhcp, $label_CurrAdapterState
Global $radio_IpAutoLabel, $radio_IpManLabel, $radio_DnsAutoLabel, $radio_DnsmanLabel, $ck_dnsRegLabel
Global $label_DnsPri, $label_DnsAlt, $ck_dnsReg, $label_ip, $label_subnet, $label_gateway
Global $buttonCopyIp, $buttonPasteIp, $buttonCopySubnet, $buttonPasteSubnet, $buttonCopyGateway, $buttonPasteGateway
Global $buttonRefresh, $buttonCopyDnsPri, $buttonPasteDnsPri, $buttonCopyDnsAlt, $buttonPasteDnsAlt
Global $searchgraphic, $filter_background, $filter_border, $lvBackground, $statusbar_background, $profilebuttons_background
Global $currentInfoBox, $setInfoBox
; TOOLBAR
Global $oToolbar, $oToolbar2, $tbButtonApply
; LANGUAGE VARIABLES
Global $oLangStrings
#EndRegion Global Variables
#include "libraries\Json\json.au3"
#include "data\adapters.au3"
#include "data\options.au3"
#include "data\profiles.au3"
#include "hexIcons.au3"
#include "languages.au3"
#include "libraries\asyncRun.au3"
#include "libraries\StringSize.au3"
#include "libraries\Toast.au3"
#include "libraries\_NetworkStatistics.au3"
#include "libraries\GuiFlatToolbar.au3"
#include "functions.au3"
#include "events.au3"
#include "network.au3"
#include "forms\_form_main.au3"
#include "forms\_form_about.au3"
#include "forms\_form_changelog.au3"
#include "forms\_form_debug.au3"
#include "forms\_form_blacklist.au3"
#include "forms\_form_settings.au3"
#include "forms\_form_update.au3"
#include "forms\_form_restart.au3"
#include "forms\_form_error.au3"
#include "cli.au3"
#Region PROGRAM CONTROL
;create the main 'objects'
$options = _Options()
$profiles = _Profiles()
$adapters = Adapter()
;initialize language strings
_initLang()
;check to see if called with command line arguments
CheckCmdLine()
;create a new window message
Global $iMsg = _WinAPI_RegisterWindowMessage('newinstance_message')
;Check if already running. If running, send a message to the first
;instance to show a popup message then close this instance.
If _Singleton("Simple IP Config", 1) = 0 Then
_WinAPI_PostMessage(0xffff, $iMsg, 0x101, 0)
Exit
EndIf
;begin main program
_main()
#EndRegion PROGRAM CONTROL
;------------------------------------------------------------------------------
; Title........: _main
; Description..: initial program setup & main running loop
;------------------------------------------------------------------------------
Func _main()
_print("starting")
_print("init lang")
; popuplate current adapter names and mac addresses
;_loadAdapters()
; get current DPI scale factor
$dscale = _GDIPlus_GraphicsGetDPIRatio()
$iDPI = $dscale * 96
;get profiles list
_loadProfiles()
_print("load profiles")
;get OS language OR selected language storage in profile
$selectedLang = $options.Language
If $selectedLang <> "" And $oLangStrings.OSLang <> $selectedLang Then
$oLangStrings.OSLang = $selectedLang
EndIf
_setLangStrings($oLangStrings.OSLang)
_print("set lang")
;make the GUI
_form_main()
_print("make GUI")
;get list of adapters and current IP info
_loadAdapters()
_print("load adapters")
;watch for new program instances
GUIRegisterMsg($iMsg, '_NewInstance')
;Add adapters the the combobox
;~ If Not IsArray($adapters) Then
;~ MsgBox(16, $oLangStrings.message.error, $oLangStrings.message.errorRetrieving)
;~ Else
;~ Adapter_Sort($adapters) ; connections sort ascending
;~ $defaultitem = Adapter_GetName($adapters, 0)
;~ $sStartupAdapter = $options.StartupAdapter
;~ If Adapter_Exists($adapters, $sStartupAdapter) Then
;~ $defaultitem = $sStartupAdapter
;~ EndIf
;~ $sAdapterBlacklist = $options.AdapterBlacklist
;~ $aBlacklist = StringSplit($sAdapterBlacklist, "|")
;~ If IsArray($aBlacklist) Then
;~ Local $adapterNames = Adapter_GetNames($adapters)
;~ For $i = 0 To UBound($adapterNames) - 1
;~ $indexBlacklist = _ArraySearch($aBlacklist, $adapterNames[$i], 1)
;~ If $indexBlacklist <> -1 Then ContinueLoop
;~ GUICtrlSetData($combo_adapters, $adapterNames[$i], $defaultitem)
;~ Next
;~ EndIf
;~ EndIf
_refresh(1)
ControlListView($hgui, "", $list_profiles, "Select", 0)
;get system double-click time
$retval = DllCall('user32.dll', 'uint', 'GetDoubleClickTime')
$mDblClickTime = $retval[0]
;see if we should display the changelog
_checkChangelog()
;get the domain
GUICtrlSetData($domainName, _DomainComputerBelongs())
$sAutoUpdate = $options.AutoUpdate
If ($sAutoUpdate = "true" Or $sAutoUpdate = "1") Then
$suppressComError = 1
_checksSICUpdate()
$suppressComError = 0
EndIf
Local $filePath
_print("Running")
While 1
;~ If $dragging Then
;~ Local $aLVHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($list_profiles))
;~ Local $iCurr_Index = $aLVHit[0]
;~ If $iCurr_Index >= $dragitem Then
;~ _GUICtrlListView_SetInsertMark($list_profiles, $iCurr_Index, True)
;~ Else
;~ _GUICtrlListView_SetInsertMark($list_profiles, $iCurr_Index, False)
;~ EndIf
;~ EndIf
If $lv_doneEditing Then
_onLvDoneEdit()
EndIf
If $lv_startEditing And Not $lv_editing Then
_onRename()
EndIf
If $movetosubnet Then
_MoveToSubnet()
EndIf
If $OpenFileFlag Then
$OpenFileFlag = 0
$filePath = FileOpenDialog($oLangStrings.dialog.selectFile, @ScriptDir, $oLangStrings.dialog.ini & " (*.ini)", $FD_FILEMUSTEXIST, "profiles.ini")
If Not @error Then
$sProfileName = $filePath
$options = _Options()
$profiles = _Profiles()
_refresh(1)
_setStatus($oLangStrings.message.loadedFile & " " & $filePath, 0)
EndIf
EndIf
If $ImportFileFlag Then
$ImportFileFlag = 0
$filePath = FileOpenDialog($oLangStrings.dialog.selectFile, @ScriptDir, $oLangStrings.dialog.ini & " (*.ini)", $FD_FILEMUSTEXIST, "profiles.ini")
If Not @error Then
_ImportProfiles($filePath)
_refresh(1)
_setStatus($oLangStrings.message.doneImporting, 0)
EndIf
EndIf
If $ExportFileFlag Then
$ExportFileFlag = 0
$filePath = FileSaveDialog($oLangStrings.dialog.selectFile, @ScriptDir, $oLangStrings.dialog.ini & " (*.ini)", $FD_PROMPTOVERWRITE, "profiles.ini")
If Not @error Then
If StringRight($filePath, 4) <> ".ini" Then
$filePath &= ".ini"
EndIf
FileCopy($sProfileName, $filePath, $FC_OVERWRITE)
_setStatus($oLangStrings.message.fileSaved & ": " & $filePath, 0)
EndIf
EndIf
If $lvTabKey And Not IsHWnd(_GUICtrlListView_GetEditControl(ControlGetHandle($hgui, "", $list_profiles))) Then
$lvTabKey = False
Send("{TAB}")
EndIf
Sleep(100)
WEnd
EndFunc ;==>_main
;------------------------------------------------------------------------------
; Title........: _NewInstance
; Description..: Called when a new program instance posts the message we were watching for.
; Bring the running program instance to the foreground.
;------------------------------------------------------------------------------
Func _NewInstance($hWnd, $iMsg, $iwParam, $ilParam)
If $iwParam == "0x00000101" Then
;~ TrayTip("", "Simple IP Config is already running", 1)
;~ $sMsg = 'Simple IP Config is already running'
;~ _Toast_Set(0, 0xAAAAAA, 0x000000, 0xFFFFFF, 0x000000, 10, "", 250, 250)
;~ $aRet = _Toast_Show(0, "Simple IP Config", $sMsg, -5, False) ; Delay can be set here because script continues
_maximize()
EndIf
EndFunc ;==>_NewInstance
Func _setProfilesIniLocation()
Local $isPortable = True
;if profiles.ini exists in the exe directory, always choose that first, otherwise check for install
If FileExists(@ScriptDir & "\profiles.ini") Then
$isPortable = True
Else
;get install path and check if running from installed or other directory
Local $sDisplayName
Local $InstallPath = _GetInstalledPath("Simple IP Config", $sDisplayName)
If @error Then
;program is not installed
$isPortable = True
Else
;program is installed, check if running from install directory
Local $scriptPath = @ScriptDir
If StringRight(@ScriptDir, 1) <> "\" Then
$scriptPath &= "\"
EndIf
If $InstallPath = $scriptPath Then
$isPortable = False
Else
$isPortable = True
EndIf
EndIf
EndIf
If $isPortable Then
$sProfileName = @ScriptDir & "\profiles.ini"
Else
If Not FileExists(@LocalAppDataDir & "\Simple IP Config") Then
DirCreate(@LocalAppDataDir & "\Simple IP Config")
EndIf
$sProfileName = @LocalAppDataDir & "\Simple IP Config\profiles.ini"
EndIf
EndFunc ;==>_setProfilesIniLocation