/*
* -----
* Screenshot Sender - __session_images.js
* -----
* Session images functions for Screenshot Sender 5
* -----
*/
var SessionImage = function () {
this.Directory = objPreferences['tSaveDirectory'];
this.Images = new Array();
}
SessionImage.prototype = {
/*
Name: GetTempPath
Purpose: Find the users temporary directory
Parameters: None
Return: Path to the users temporary directory
*/
"GetTempPath" : function () {
var sBuffer = Interop.Allocate(512);
Interop.Call('kernel32', 'GetTempPathW', 100, sBuffer);
return sBuffer.ReadString(0);
},
/*
Name: GetTempFilename
Purpose: Create a temporary file
Parameters: sPath - Path to the temporary file
Return: Path including the temporary file name
*/
"GetTempFilename" : function (sPath) {
var sBuffer = Interop.Allocate(512);
Interop.Call('kernel32', 'GetTempFileNameW', sPath, 'ss5', 0, sBuffer);
return sBuffer.ReadString(0);
},
/*
Name: CreateImagePath
Purpose: Add the new filename to our array for session images
Parameters: None
Return: Location of new image to be written
*/
"CreateImagePath" : function () {
MakeFolder(this.Directory);
return this.Images[this.Images.push(this.Directory+this.FilenameQuickTexts(objPreferences['tFilename']) +this.AppendExt() ) -1];
},
/*
Name: CreateTempImage
Purpose: Creates a temporary file so that we can save our image temporarily
Parameters: None
Return: Path to the temporary file
*/
"CreateTempImage" : function () {
var _file = this.GetTempFilename(this.GetTempPath());
Interop.Call('kernel32', 'DeleteFileW', _file);
return _file+this.AppendExt();
},
/*
Name: AppendExt
Purpose: Returns an extension based on user preference
Parameters: None
Return: Extension
*/
"AppendExt" : function() {
return '.'+aImageFormats[objPreferences['cFileType']].toLowerCase();
},
/*
Name: MoveTempImage
Purpose: Move the temporary image to the location of the new file
Parameters: _tmp_file - Location to the temporary file
_new_file - Location to the new file
Return: Path of the new image
*/
"MoveTempImage" : function (_tmp_file, _new_file) {
while (FileExists(_new_file) ) _new_file = this.CreateImagePath();
Interop.Call('kernel32', 'MoveFileW', _tmp_file, _new_file);
Interop.Call('kernel32', 'DeleteFileW', _tmp_file);
if (objPreferences['cShowSaveConfirm'] == 1) {
var sMessage = sReplace( _lang.text['MsgBoxSaveSuccessful'], [this.GetFilename(_new_file)] );
Interop.Call('user32', 'MessageBoxW', 0, sMessage, _lang.text['MsgBoxSaveSuccessful_Title'], 32);
}
return _new_file;
},
/*
Name: FilenameQuickTexts
Purpose: Replace quick texts in the filename
Parameters: sFile - Name of the file to replace specific chars
Return: New edited string
*/
"FilenameQuickTexts" : function (sFile, bOverlayText) {
if (typeof bOverlayText === TYPE_UNDEFINED) bOverlayText = false;
if (sFile.indexOf('!#') > -1) {
if (bOverlayText === true) {
sFile = sFile.replace(/!#/g, objPreferences['lFileNumber']-1<10?'0':'')+objPreferences['lFileNumber']-1;
} else {
sFile = sFile.replace(/!#/g, objPreferences['lFileNumber']<10?'0':'')+objPreferences['lFileNumber'];
objPreferences['lFileNumber']++;
Registry_SetKeyValue(HKCU, RegistryInit(), 'lFileNumber', objPreferences['lFileNumber'], REG_DWORD);
}
}
sFile = sFile.replace(/!(time24|time)/gi, this.GetTime() );
sFile = sFile.replace(/!date/gi, this.GetDate() );
sFile = sFile.replace(/!email/gi, Messenger.MyEmail);
return (bOverlayText?sFile:sFile.replace(/[\\/:*>""<>\|]/g, ''));
},
/*
Name: GetDate
Purpose: Get the current date in the users locale
Parameters: None
Return: The current date in string format
*/
"GetDate" : function () {
var SYSTEMTIME = Interop.ALlocate(16);
var sDate = Interop.Allocate(512);
Interop.Call('kernel32', 'GetSystemTime', SYSTEMTIME);
Interop.Call('kernel32', 'GetDateFormatW', 0x400 /* LOCALE_USER_DEFAULT */, 0, SYSTEMTIME, 0, sDate, 512);
return sDate.ReadString(0);
},
/*
Name: GetTime
Purpose: Get the current time in the users locale
Parameters: None
Return: The current time im string format
*/
"GetTime" : function () {
var SYSTEMTIME = Interop.ALlocate(16);
var sTime = Interop.Allocate(512);
Interop.Call('kernel32', 'GetLocalTime', SYSTEMTIME);
Interop.Call('kernel32', 'GetTimeFormatW', 0x800 /* LOCALE_USER_DEFAULT */, 0, SYSTEMTIME, 0, sTime, 512);
return sTime.ReadString(0);
},
/*
Name: DeleteSessionImages
Purpose: Deletes the images created in the users session
Parameters: None
Return: None
*/
"DeleteSessionImages" : function () {
if (objPreferences['cDeleteSessionImages'] === 1) {
for (var j in this.SessionImages.Images) Interop.Call('kernel32', 'DeleteFileW', this.SessionImages.Images[j]);
}
},
"GetFilename" : function (s) {
var regex = /.*\\([^\\]+)$/;
try {
return regex.exec(s)[1];
} catch (e) {
return s;
}
},
/*
Name: GetExtension
Purpose: Get the extension of the passed string
Parameters: s - The string to find the extension of
Return: The extension of the file
*/
"GetExtension" : function (s) {
var regex = /\.([^\.]+)$/;
try {
return regex.exec(s)[1];
} catch (e) {
return s;
}
}
}