Тема: JScript: Фреймворк
Приветствую. Поделюсь мыслями. Честно говоря, давно не вижу развития скриптинга под JScript в среде WSH. Возможно это связано тем, что довольно часто код пишется "с нуля", что явно тормозит разработку. Аналогичная ситуация была с JavaScript довольно недавно в браузерах. Несмотря на скептицизм, который был распространен в то время, фреймворки позволили оживить странички на более продвинутом уровне. А сейчас и они сплошь и рядом.
В общем, я написал ряд функций, которые позволят упростить жизнь разработчиков в определенных случаях.
Фреймворк является принципиально плоским, а названия и функционал функций взяты из языка программирования AutoIt. В общем, буду рад единомышленникам, а также надеюсь, что это пригодится кому-нибудь.
В настоящее время реализованы следующие функции:
Enumerator.prototype.toArray
Function.prototype.bind
String.prototype.trim
Array.prototype.indexOf
Array.prototype.lastIndexOf
Array.prototype.forEach
Array.prototype.map
Array.prototype.filter
Array.prototype.every
Array.prototype.some
GenerateString()
WMIQuery()
MsgBox
GetAppDataCommonDir()
GetAppDataDir()
GetExe()
GetPID()
GetCommonFilesDir()
GetComputerName()
GetComSpec()
GetCPUArc()
GetDesktopCommonDir()
GetDesktopDir()
GetDocumentsCommonDir()
GetFavoritesCommonDir()
GetFavoritesDir()
GetMyDocumentsDir()
GetHomePath()
GetHomeDrive()
GetStartMenuCommonDir()
GetStartMenuDir()
GetUserProfileDir()
GetSystemDir()
GetTempDir()
GetProgramFilesDir()
GetProgramsCommonDir()
GetProgramsDir()
GetWindowsDir()
GetWorkingDir()
GetScriptDir()
GetScriptFullPath()
GetScriptName()
GetDesktopHeight()
GetDesktopWidth()
GetDesktopDepth()
GetHOUR()
GetMDAY()
GetMIN()
GetMON()
GetMSEC()
GetSEC()
GetWDAY()
GetYDAY()
GetYEAR()
GetFULLDATE()
GetUserName()
GetLogonServer()
GetIPAddress1()
GetMacAddress()
GetPublicIPAddress()
GetOSArch()
GetOSBuild()
GetOSLang()
GetOSInstallDate()
GetOSServicePack()
GetOSVersion()
ProcessClose(ProcName)
ProcessExists(ProcName)
ProcessWait(process, timeout=0)
ProcessWaitClose(process, timeout=0)
13/11/2013
DirCopy Copies a directory and all sub-directories and files (Similar to xcopy).
DirCreate Creates a directory/folder.
FileDelete Delete one or more files. (принудительное удаление. принимает как массивы файлов, так и просто путь) поддерживает удаление по маске.
FileExists Checks if a file or directory exists.
DirMove Moves a directory and all sub-directories and files
FileMove Moves one or more files
DirRemove Deletes a directory/folder.
FileCopy Copies one or more files.
DriveGetDrive Returns an array containing the enumerated drives.
FileGetVersion Returns the "File" version information.
FileChangeDir Changes the current working directory.
DriveGetFileSystem Returns File System Type of a drive.
DriveGetLabel Returns Volume Label of a drive, if it has one.
DriveGetSerial Returns Serial Number of a drive.
DriveGetType Returns drive type.
DriveMapAdd Maps a network drive.
DriveMapDel Disconnects a network drive.
DriveMapGet Retrieves the details of a mapped drive.
DriveSetLabel Sets the Volume Label of a drive.
DriveSpaceFree Returns the free disk space of a path in Megabytes.
DriveSpaceTotal Returns the total disk space of a path in Megabytes.
DriveStatus Returns the status of the drive as a string.
15/11/13:
StringCompare Compares two strings with options.
StringInStr Checks if a string contains a given substring.
StringIsAlNum Checks if a string contains only alphanumeric characters.
StringIsAlpha Checks if a string contains only alphabetic characters.
StringIsASCII Checks if a string contains only ASCII characters in the range 0x00 - 0x7f (0 - 127).
StringIsDigit Checks if a string contains only digit (0-9) characters.
StringIsFloat Checks if a string is a floating point number.
StringIsInt Checks if a string is an integer.
StringIsLower Checks if a string contains only lowercase characters.
StringIsSpace Checks if a string contains only whitespace characters.
StringIsUpper Checks if a string contains only uppercase characters.
StringIsXDigit Checks if a string contains only hexadecimal digit (0-9, A-F) characters.
StringLeft Returns a number of characters from the left-hand side of a string.
StringLen Returns the number of characters in a string.
StringLower Converts a string to lowercase.
StringMid Extracts a number of characters from a string.
StringRight Returns a number of characters from the right-hand side of a string.
StringStripCR Removes all carriage return values ( Chr(13) ) from a string.
StringStripWS Strips the white space in a string.
StringTrimLeft Trims a number of characters from the left hand side of a string.
StringTrimRight Trims a number of characters from the right hand side of a string.
StringUpper Converts a string to uppercase. Asc Returns the ASCII code of a character.
19/11/13:
StringAddCR Takes a string and prefixes all linefeed characters ( Chr(10) ) with a carriage return character ( Chr(13) ).
StringFormat Returns a formatted string (similar to the C sprintf() function).
StringFromASCIIArray Converts an array of ASCII codes to a string.
StringReplace Replaces substrings in a string.
StringSplit Splits up a string into substrings depending on the given delimiters.
StringToASCIIArray Converts a string to an array containing the ASCII code of each character.
printf
sprintf
27.03.14:
ProcessList Returns an array listing the currently running processes (names and PIDs).
Sleep Pause script execution.
AscW Returns the unicode code of a character.
Asc Returns the ASCII code of a character.
ChrW Returns a character corresponding to a unicode code.
Chr Returns a character corresponding to an ASCII code.
TimerInit Returns a handle that can be passed to TimerDiff() to calculate the difference in milliseconds.
TimerDiff Returns the difference in time from a previous call to TimerInit().
Hex Returns a string representation of an integer or of a binary type converted to hexadecimal.
Dec Returns a numeric representation of a hexadecimal string.
ProcessGetStats Returns an array about Memory or IO infos of a running process.
ProcessSetPriority Changes the priority of a process
FileGetTime Returns the time and date information for a file.
IsAdmin Checks if the current user has full administrator privileges.
ClipGet Retrieves text from the clipboard.
ClipPut Writes text to the clipboard.
FileSelectFolder Initiates a Browse For Folder dialog.
Run Runs an external program.
RunWait Runs an external program and pauses script execution until the program finishes.
FileGetShortName Returns the 8.3 short path+name of the path+name passed.
FileGetLongName Returns the long path+name of the path+name passed.
FileGetSize Returns the size of a file in bytes.
DirGetSize Returns the size in bytes of a given directory.
EnvGet Retrieves an environment variable.
FileCreateShortcut Creates a shortcut (.lnk) to a file.
FileGetShortcut Retrieves details about a shortcut.
FileSearch
FileSearchStop
FileSearchAll
FileFindFirst
FileSetTime Sets the timestamp of one of more files.
FileGetAttrib Returns a code string representing a file's attributes.
FileSetAttrib Sets the attributes of one or more files.
ShellExecute Runs an external program using the ShellExecute API.
ShellExecuteWait Runs an external program using the ShellExecute API and pauses script execution until it finishes.
MemGetStats Retrieves memory related information.
RegDelete Deletes a key or value from the registry.
09/04/2014
FileGetEncoding Determines the text encoding used in a file.
Функции работы с реестром, поддержка работы с удаленными машинами.
RegEnumValues Reads the name of a value according to its instance.
RegRead Reads the value in a registry.
RegWriteValue Writes the value in a registry. // поддержка всех типов данных
RegEnumKeys Reads the name of a subkey according to its instance.
RegCreateKey Creates the key in a registry.
RegWrite Creates key or writes the value in a registry.
RegCheckKeyAccess
RegDeleteKey
RegDeleteValue
RegDelete Deletes a key or value from the registry.
Работа с INI-файлами.
INIGetObject Парсинг ini-файла. Возвращает специальный объект.
INISaveObject Save the object to a file.
IniReadSectionNames Reads all sections in a standard format .ini file.
IniReadSection Reads all key/value pairs from a section in a standard format .ini file.
IniRead Reads a value from a standard format .ini file.
IniRenameSection Renames a section in a standard format .ini file.
IniDelete Deletes a value from a standard format .ini file.
IniWriteSection Writes a section to a standard format .ini file.
IniWrite Writes a value to a standard format .ini file.
Код прикреплен к посту.
А эти функции будут реализованы в ближайшее время
FileClose Closes a previously opened text file.
FileFlush Flushes the file's buffer to disk.
FileGetPos Retrieves the current file position.
FileInstall Include and install a file with the compiled script.
FileOpen Opens a text file for reading or writing.
FileOpenDialog Initiates a Open File Dialog.
FileRead Read in a number of characters from a previously opened text file.
FileReadLine Read in a line of text from a previously opened text file.
FileRecycle Sends a file or directory to the recycle bin.
FileRecycleEmpty Empties the recycle bin.
FileSaveDialog Initiates a Save File Dialog.
FileSetPos Sets the current file position.
FileWrite Append a text/data to the end of a previously opened file.
FileWriteLine Append a line of text to the end of a previously opened text file.
Binary Returns the binary representation of an expression.
BinaryLen Returns the number of bytes in a binary variant.
BinaryMid Extracts a number of bytes from a binary variant.
BinaryToString Converts a binary variant into a string.
StringToBinary Converts a string into binary data.
RunAs Runs an external program under the context of a different user.
RunAsWait Runs an external program under the context of a different user and pauses script execution until the program finishes.
Shutdown Shuts down the system.
StderrRead Reads from the STDERR stream of a previously run child process.
StdinWrite Writes a number of characters to the STDIN stream of a previously run child process.
StdioClose Closes all resources associated with a process previously run with STDIO redirection.
StdoutRead Reads from the STDOUT stream of a previously run child process.
FtpSetProxy Sets the internet proxy to use for ftp access.
HttpSetProxy Sets the internet proxy to use for http access.
HttpSetUserAgent Sets the user-agent string sent with InetGet() and InetRead() requests.
InetClose Closes a handle returned from InetGet().
InetGet Downloads a file from the internet using the HTTP, HTTPS or FTP protocol.
InetGetInfo Returns detailed data for a handle returned from InetGet().
InetGetSize Returns the size (in bytes) of a file located on the internet.
InetRead Downloads a file from the internet using the HTTP, HTTPS or FTP protocol.
Ping Pings a host and returns the roundtrip-time.
EnvSet Writes an environment variable.
EnvUpdate Refreshes the OS environment.
Отредактировано 09/04/14