| 772 | |
| 773 | |
| 774 | LineNumberType Script::LoadFromFile() |
| 775 | // Returns the number of non-comment lines that were loaded, or LOADING_FAILED on error. |
| 776 | { |
| 777 | mNoHotkeyLabels = true; // Indicate that there are no hotkey labels, since we're (re)loading the entire file. |
| 778 | mIsReadyToExecute = AutoExecSectionIsRunning = false; |
| 779 | if (!mFileSpec || !*mFileSpec) return LOADING_FAILED; |
| 780 | |
| 781 | #ifndef AUTOHOTKEYSC // When not in stand-alone mode, read an external script file. |
| 782 | DWORD attr = GetFileAttributes(mFileSpec); |
| 783 | if (attr == MAXDWORD) // File does not exist or lacking the authorization to get its attributes. |
| 784 | { |
| 785 | char buf[MAX_PATH + 256]; |
| 786 | snprintf(buf, sizeof(buf), "The script file \"%s\" does not exist. Create it now?", mFileSpec); |
| 787 | int response = MsgBox(buf, MB_YESNO); |
| 788 | if (response != IDYES) |
| 789 | return 0; |
| 790 | FILE *fp2 = fopen(mFileSpec, "a"); |
| 791 | if (!fp2) |
| 792 | { |
| 793 | MsgBox("Could not create file, perhaps because the current directory is read-only" |
| 794 | " or has insufficient permissions."); |
| 795 | return LOADING_FAILED; |
| 796 | } |
| 797 | fputs( |
| 798 | "; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a\n" |
| 799 | "; semicolon, such as this one, are comments. They are not executed.\n" |
| 800 | "\n" |
| 801 | "; This script is a .INI file because it is a special script that is\n" |
| 802 | "; automatically launched when you run the program directly. By contrast,\n" |
| 803 | "; text files that end in .ahk are associated with the program, which\n" |
| 804 | "; means that they can be launched simply by double-clicking them.\n" |
| 805 | "; You can have as many .ahk files as you want, located in any folder.\n" |
| 806 | "; You can also run more than one .ahk file simultaneously and each will\n" |
| 807 | "; get its own tray icon.\n" |
| 808 | "\n" |
| 809 | "; Please read the QUICK-START TUTORIAL near the top of the help file.\n" |
| 810 | "; It explains how to perform common automation tasks such as sending\n" |
| 811 | "; keystrokes and mouse clicks. It also explains how to use hotkeys.\n" |
| 812 | "\n" |
| 813 | "; SAMPLE HOTKEYS: Below are two sample hotkeys. The first is Win+Z and it\n" |
| 814 | "; launches a web site in the default browser. The second is Control+Alt+N\n" |
| 815 | "; and it launches a new Notepad window (or activates an existing one). To\n" |
| 816 | "; try out these hotkeys, run AutoHotkey again, which will load this file.\n" |
| 817 | "\n" |
| 818 | "#z::Run, www.autohotkey.com\n" |
| 819 | "\n" |
| 820 | "^!n::\n" |
| 821 | "IfWinExist, Untitled - Notepad\n" |
| 822 | "\tWinActivate\n" |
| 823 | "else\n" |
| 824 | "\tRun, Notepad\n" |
| 825 | "return\n" |
| 826 | "\n" |
| 827 | "\n" |
| 828 | "; Note: From now on whenever you run AutoHotkey directly, this script\n" |
| 829 | "; will be loaded. So feel free to customize it to suit your needs.\n" |
| 830 | , fp2); |
| 831 | fclose(fp2); |
no test coverage detected