Image Uploader Scripting API: ScriptAPI Namespace Reference

| Image Uploader Scripting API

Classes | Functions
ScriptAPI Namespace Reference

Namespace containing functions and classes available in squirrel scripts. More...

## Classes

class | CWebBrowser
class | Document
class | FileUploadTask
class | HtmlDocument
class | HtmlElement
class | Process
| The Process class is used to start external programs and to communicate with them. More...
class | CRegExp
class | UploadTask
class | UrlShorteningTask
class | WebServer
| Start a web server listening a port on 127.0.0.1. More...

## Functions

string | AnsiToUtf8 (string str, int codepage)
string | AskUserCaptcha (NetworkClient *nm, string url)
| Shows the captcha input dialog. More...
string | Base64Decode (string data)
string | Base64Encode (string data)
bool | CopyFile (string source, string destination, bool overwrite)
bool | CreateDirectory (string path_, unsigned int mode)
void | DebugMessage (string msg, bool isResponseBody)
| Shows a dialog box with a diagnostic message.
bool | DeleteFile (string utf8Filename)
string | ExtractFileName (string path)
string | ExtractFileNameNoExt (string fileName)
string | ExtractFilePath (string fileName)
bool | FileExists (string fileName)
string | GetAppLanguage ()
string | GetAppLanguageFile ()
string | GetAppLocale ()
table | GetAppVersion ()
string | GetCurrentThreadId ()
string | GetDeviceId ()
string | GetDeviceName ()
string | GetFileContents (string filename)
string | GetFileExtension (string path)
string | GetFileMimeType (string filename)
int | GetFileSize (string filename)
double | GetFileSizeDouble (string filename)
table | GetImageInfo (string fileName)
string | GetScriptsDirectory ()
string | GetTempDirectory ()
string | hmac_sha1 (string key, string data, bool base64)
string | HmacSha1 (string key, string data, bool base64)
string | HtmlEntitiesDecode (string src)
object | include (string filename)
string | InputDialog (string text, string defaultValue)
string | JsonEscapeString (string src)
string | Md5 (string data)
| Calculates the md5 hash of a string. More...
string | md5 (string data)
| Calculates the md5 hash of a string. More...
string | md5_file (string filename)
| Calculates the md5 hash of a given file. More...
string | Md5FromFile (string filename)
| Calculates the md5 hash of a given file. More...
string | MessageBox (string message, string title, string buttons, string type)
bool | MoveFileOrFolder (string from, string to)
object | ParseJSON (string json)
bool | PutFileContents (string utf8Filename, string content)
int | Random ()
int | random ()
string | Sha1 (string data)
string | sha1 (string data)
string | sha1_file (string filename)
string | sha1_file_prefix (string filename, string prefix, string postfix)
string | Sha1FromFile (string filename)
string | Sha1FromFileWithPrefix (string filename, string prefix, string postfix)
string | Sha256 (string data)
string | Sha256FromFile (string filename, int offset, size_t chunkSize)
bool | ShellOpenUrl (string url)
void | Sleep (int msec)
void | sleep (int msec)
string | ToJSON (object obj)
string | Translate (string key, string originalText)
string | url_encode (string value)
string | UrlEncode (string value)
string | Utf8ToAnsi (string str, int codepage)

## Detailed Description

Namespace containing functions and classes available in squirrel scripts.

## Function Documentation

## ◆ AnsiToUtf8()

string ScriptAPI::AnsiToUtf8 | ( | string | str,
|  | int | codepage
| ) |  |

Converts a string from ANSI encoding to UTF-8.

You can find the codepage number you need here:

https://raw.githubusercontent.com/zenden2k/image-uploader/master/Source/Core/3rdpart/CodePages.cpp

Available only in Windows.

## ◆ AskUserCaptcha()

string ScriptAPI::AskUserCaptcha | ( | NetworkClient * | nm,
|  | string | url
| ) |  |

Shows the captcha input dialog.

nm - network manager, url - address of the image with captcha. The return value is the text entered by the user.

## ◆ CreateDirectory()

bool ScriptAPI::CreateDirectory | ( | string | path_,
|  | unsigned int | mode
| ) |  |

Creates a directory (recursively). The mode parameter is ignored in Windows.

## ◆ ExtractFileNameNoExt()

string ScriptAPI::ExtractFileNameNoExt | ( | string | fileName | ) |

Extract the file name without extension from the path.

Since
  1.3.0

## ◆ ExtractFilePath()

string ScriptAPI::ExtractFilePath | ( | string | fileName | ) |

Extract directory name from path.

Since
  1.3.0

## ◆ FileExists()

bool ScriptAPI::FileExists | ( | string | fileName | ) |

Checks if a file exists.

Since
  1.3.0

## ◆ GetAppLanguage()

string ScriptAPI::GetAppLanguage | ( |  | ) |

Returns application's current language. For example : "en", "ru".

## ◆ GetAppLanguageFile()

string ScriptAPI::GetAppLanguageFile | ( |  | ) |

Returns name of the application's current language file (without .lng extension). For example: "English", "Russian".

Since
  1.3.1

## ◆ GetAppLocale()

string ScriptAPI::GetAppLocale | ( |  | ) |

Returns application's current locale. For example : "en_US", "ru_RU".

## ◆ GetAppVersion()

table ScriptAPI::GetAppVersion | ( |  | ) |

Returns a table containing information about application's version. For example:

{
Major = 1,
Minor = 3,
Release = 1,
Build = 4240,
Gui = true
}

Since
  1.3.1

## ◆ GetCurrentThreadId()

string ScriptAPI::GetCurrentThreadId | ( |  | ) |

Retrieves the thread identifier of the calling thread.

## ◆ GetFileContents()

string ScriptAPI::GetFileContents | ( | string | filename | ) |

Since
  1.3.0

## ◆ GetFileMimeType()

string ScriptAPI::GetFileMimeType | ( | string | filename | ) |

Returns the MIME file type (for example, "text / html"), analyzing the contents of the file. File must exist. (in Windows, the FindMimeFromData function is used. In unix, the command 'file -b –mime-type' is used.).

## ◆ GetFileSize()

int ScriptAPI::GetFileSize | ( | string | filename | ) |

Returns the size of the file in bytes.

Since
  1.3.0

## ◆ GetFileSizeDouble()

double ScriptAPI::GetFileSizeDouble | ( | string | filename | ) |

Returns the size of the file in bytes (for files greater than 2 GB).

Since
  1.3.0

Deprecated:

## ◆ GetImageInfo()

table ScriptAPI::GetImageInfo | ( | string | fileName | ) |

Returns a table containing information about image. For example:

{
Width = 640,
Height = 480
}

Since
  1.3.2.4616

## ◆ GetScriptsDirectory()

string ScriptAPI::GetScriptsDirectory | ( |  | ) |

Returns path to squirrel scripts directory.

Since
  1.3.1

## ◆ GetTempDirectory()

string ScriptAPI::GetTempDirectory | ( |  | ) |

Returns the directory for temporary files

Since
  1.3.0

## ◆ hmac_sha1()

string ScriptAPI::hmac_sha1 | ( | string | key,
|  | string | data,
|  | bool | base64
| ) |  |

Generate a keyed hash value using the HMAC method and sha1 hashing algorythm

Parameters

  data | Message to be hashed.
  key | Shared secret key used for generating the HMAC variant of the message digest.
  base64 | Generate in base64 format

Deprecated:
  since 1.4.0

See also
  HmacSha1

## ◆ HmacSha1()

string ScriptAPI::HmacSha1 | ( | string | key,
|  | string | data,
|  | bool | base64
| ) |  |

Generate a keyed hash value using the HMAC method and sha1 hashing algorythm

Parameters

  data | Message to be hashed.
  key | Shared secret key used for generating the HMAC variant of the message digest.
  base64 | Generate in base64 format

Since
  1.4.0

## ◆ include()

object ScriptAPI::include | ( | string | filename | ) |

Includes and runs the script from file. filename should be relative to the scripts root directory.

Deprecated:
  since 1.4.0 Use IO library's dofile() instead.

## ◆ InputDialog()

string ScriptAPI::InputDialog | ( | string | text,
|  | string | defaultValue
| ) |  |

Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String containing the contents of the text box.

Parameters

  defaultValue | Default text displayed in text box

## ◆ JsonEscapeString()

string ScriptAPI::JsonEscapeString | ( | string | src | ) |

Escapes a string for use in JSON. Returns a string with quotes.

Deprecated:
  Instead, use the ToJSON function.

## ◆ Md5()

string ScriptAPI::Md5 | ( | string | data | ) |

Calculates the md5 hash of a string.

Since
  1.4.0

## ◆ md5()

string ScriptAPI::md5 | ( | string | data | ) |

Calculates the md5 hash of a string.

Deprecated:
  since 1.4.0

## ◆ md5_file()

string ScriptAPI::md5_file | ( | string | filename | ) |

Calculates the md5 hash of a given file.

Since
  1.2.7.4176

Deprecated:
  since 1.4.0

See also
  Md5FromFile

## ◆ Md5FromFile()

string ScriptAPI::Md5FromFile | ( | string | filename | ) |

Calculates the md5 hash of a given file.

Since
  1.4.0

## ◆ MessageBox()

string ScriptAPI::MessageBox | ( | string | message,
|  | string | title,
|  | string | buttons,
|  | string | type
| ) |  |

Shows a dialog box with a message

buttons possible values: OK, YES_NO, YES_NO_CANCEL, ABORT_RETRY_IGNORE,CANCEL_TRY_CONTINUE, OK_CANCEL, RETRY_CANCEL

type possible values: EXCLAMATION, WARNING, INFORMATION, QUESTION, ERROR

Returns
  Title of the clicked button ( ABORT,CANCEL, CONTINUE, IGNORE, YES, NO, OK, TRY).

## ◆ MoveFileOrFolder()

bool ScriptAPI::MoveFileOrFolder | ( | string | from,
|  | string | to
| ) |  |

Renames/moves a file or folder.

Since
  1.3.0

## ◆ ParseJSON()

object ScriptAPI::ParseJSON | ( | string | json | ) |

Converts text containing a JSON document, into a table (associative container made in the form of key / value pairs) or an array. For example, the original JSON document:

{
"result": {
"success": true,
"links": [
{
"href": "http://example.com/thumb.jpg"
},
{
"href": "http://example.com/image.jpg"
}
]
}
}

Squirrel script:

local t = ParseJSON(text);
print(t.result.links[1].href); // will print "http://example.com/image.jpg"

Returns
  In case of error function retuns null.

Since
  1.3.0

## ◆ PutFileContents()

bool ScriptAPI::PutFileContents | ( | string | utf8Filename,
|  | string | content
| ) |  |

Write data to a file

Since
  1.3.0

## ◆ Random()

int ScriptAPI::Random | ( |  | ) |

Returns a random number.

Since
  1.4.0

## ◆ random()

int ScriptAPI::random | ( |  | ) |

Returns a random number.

Deprecated:
  since 1.4.0

See also
  Random

## ◆ Sha1()

string ScriptAPI::Sha1 | ( | string | data | ) |

Calculates the sha1-hash of a given string

Since
  1.4.0

## ◆ sha1()

string ScriptAPI::sha1 | ( | string | data | ) |

Calculates the sha1-hash of a given string

Since
  1.2.7.4176

Deprecated:
  since 1.4.0

See also
  Sha1

## ◆ sha1_file()

string ScriptAPI::sha1_file | ( | string | filename | ) |

Calculates the sha1-hash of a given file

Since
  1.2.7.4176

Deprecated:
  since 1.4.0

See also
  Sha1FromFile

## ◆ sha1_file_prefix()

string ScriptAPI::sha1_file_prefix | ( | string | filename,
|  | string | prefix,
|  | string | postfix
| ) |  |

Calculates the sha1-hash of a given file, prepeding file with prefix and adding postfix at the end while calculating hash

Since
  1.3.3

Deprecated:
  since 1.4.0

See also
  Sha1FromFileWithPrefix

## ◆ Sha1FromFile()

string ScriptAPI::Sha1FromFile | ( | string | filename | ) |

Calculates the sha1-hash of a given file

Since
  1.4.0

## ◆ Sha1FromFileWithPrefix()

string ScriptAPI::Sha1FromFileWithPrefix | ( | string | filename,
|  | string | prefix,
|  | string | postfix
| ) |  |

Calculates the sha1-hash of a given file, prepeding file with prefix and adding postfix at the end while calculating hash

Since
  1.4.0

## ◆ Sha256()

string ScriptAPI::Sha256 | ( | string | data | ) |

Calculates the sha256-hash of a given string

Since
  1.4.0

## ◆ Sha256FromFile()

string ScriptAPI::Sha256FromFile | ( | string | filename,
|  | int | offset,
|  | size_t | chunkSize
| ) |  |

Calculates the sha256-hash of a given file

Since
  1.4.0

## ◆ ShellOpenUrl()

bool ScriptAPI::ShellOpenUrl | ( | string | url | ) |

Opens a URL/file in a standard browser/associated application.

Since
  1.2.9.4185

## ◆ Sleep()

void ScriptAPI::Sleep | ( | int | msec | ) |

The script falls asleep for the specified number of milliseconds.

Since
  1.4.0

## ◆ sleep()

void ScriptAPI::sleep | ( | int | msec | ) |

The script falls asleep for the specified number of milliseconds.

Deprecated:
  since 1.4.0

See also
  Sleep

## ◆ Translate()

string ScriptAPI::Translate | ( | string | key,
|  | string | originalText
| ) |  |

Returns text translated into the currently selected language. Every user-visible string in the script must be wrapped into this function. Translating scripts into different languages

## ◆ url_encode()

string ScriptAPI::url_encode | ( | string | value | ) |

URL-encodes string. This function is convenient when encoding a string to be used in a query part of a URL.

Use NetworkClient's nm.urlEncode() when possible instead.

Deprecated:
  since 1.4.0

See also
  UrlEncode

## ◆ UrlEncode()

string ScriptAPI::UrlEncode | ( | string | value | ) |

URL-encodes string. This function is convenient when encoding a string to be used in a query part of a URL.

Use NetworkClient's nm.urlEncode() when possible instead.

Since
  1.4.0

## ◆ Utf8ToAnsi()

string ScriptAPI::Utf8ToAnsi | ( | string | str,
|  | int | codepage
| ) |  |

Converts a string from ANSI encoding to UTF-8.

You can find the codepage number you need here:

https://raw.githubusercontent.com/zenden2k/image-uploader/master/Source/Core/3rdpart/CodePages.cpp

Available only in Windows.

ScriptAPI::ParseJSON
object ParseJSON(string json)