Code Viewer

./Classes/__session_images.js File Size: 10.76 KB

  1. /*
  2. * -----
  3. * Screenshot Sender - __session_images.js
  4. * -----
  5. * Session images functions for Screenshot Sender 5
  6. * -----
  7. */
  8.  
  9. var SessionImage = function () {
  10.         this.Directory = objPreferences['tSaveDirectory'];
  11.         this.Images = new Array();
  12. }
  13.  
  14. SessionImage.prototype = {
  15.         /*
  16.                 Name:   GetTempPath
  17.                 Purpose:        Find the users temporary directory
  18.                 Parameters:     None
  19.                 Return: Path to the users temporary directory
  20.         */
  21.         "GetTempPath" : function () {
  22.                         var sBuffer = Interop.Allocate(512);
  23.                         Interop.Call('kernel32', 'GetTempPathW', 100, sBuffer);
  24.                         return sBuffer.ReadString(0);
  25.         },
  26.  
  27.         /*
  28.                 Name:   GetTempFilename
  29.                 Purpose:        Create a temporary file
  30.                 Parameters:     sPath - Path to the temporary file
  31.                 Return: Path including the temporary file name
  32.         */
  33.         "GetTempFilename" : function (sPath) {
  34.                         var sBuffer = Interop.Allocate(512);
  35.                         Interop.Call('kernel32', 'GetTempFileNameW', sPath, 'ss5', 0, sBuffer);
  36.                         return sBuffer.ReadString(0);
  37.         },
  38.  
  39.         /*
  40.                 Name:   CreateImagePath
  41.                 Purpose:        Add the new filename to our array for session images
  42.                 Parameters:     None
  43.                 Return: Location of new image to be written
  44.         */
  45.         "CreateImagePath" : function () {
  46.                         MakeFolder(this.Directory);
  47.                         return this.Images[this.Images.push(this.Directory+this.FilenameQuickTexts(objPreferences['tFilename']) +this.AppendExt() ) -1];
  48.         },
  49.  
  50.         /*
  51.                 Name:   CreateTempImage
  52.                 Purpose:        Creates a temporary file so that we can save our image temporarily
  53.                 Parameters:     None
  54.                 Return: Path to the temporary file
  55.         */
  56.         "CreateTempImage" : function () {
  57.                         var _file = this.GetTempFilename(this.GetTempPath());
  58.                         Interop.Call('kernel32', 'DeleteFileW', _file);
  59.                         return _file+this.AppendExt();
  60.         },
  61.         /*
  62.                 Name:   AppendExt
  63.                 Purpose:        Returns an extension based on user preference
  64.                 Parameters:     None
  65.                 Return: Extension
  66.         */
  67.         "AppendExt" : function() {
  68.                 return '.'+aImageFormats[objPreferences['cFileType']].toLowerCase();
  69.         },
  70.        
  71.         /*
  72.                 Name:   MoveTempImage
  73.                 Purpose:        Move the temporary image to the location of the new file
  74.                 Parameters:     _tmp_file - Location to the temporary file
  75.                                 _new_file - Location to the new file
  76.                 Return: Path of the new image
  77.         */
  78.         "MoveTempImage" : function (_tmp_file, _new_file) {
  79.                         while (FileExists(_new_file) ) _new_file = this.CreateImagePath();
  80.                        
  81.                         Interop.Call('kernel32', 'MoveFileW', _tmp_file, _new_file);
  82.                         Interop.Call('kernel32', 'DeleteFileW', _tmp_file);
  83.                        
  84.                         if (objPreferences['cShowSaveConfirm'] == 1) {
  85.                                 var sMessage = sReplace( _lang.text['MsgBoxSaveSuccessful'], [this.GetFilename(_new_file)] );
  86.                                 Interop.Call('user32', 'MessageBoxW', 0, sMessage, _lang.text['MsgBoxSaveSuccessful_Title'], 32);
  87.                         }
  88.                         return _new_file;
  89.         },
  90.  
  91.         /*
  92.                 Name:   FilenameQuickTexts
  93.                 Purpose:        Replace quick texts in the filename
  94.                 Parameters:     sFile - Name of the file to replace specific chars
  95.                 Return: New edited string
  96.         */
  97.         "FilenameQuickTexts" : function (sFile, bOverlayText) {
  98.                 if (typeof bOverlayText === TYPE_UNDEFINED) bOverlayText = false;
  99.                 if (sFile.indexOf('!#') > -1) {
  100.                         if (bOverlayText === true) {
  101.                                 sFile = sFile.replace(/!#/g, objPreferences['lFileNumber']-1<10?'0':'')+objPreferences['lFileNumber']-1;
  102.                         } else {
  103.                                 sFile = sFile.replace(/!#/g, objPreferences['lFileNumber']<10?'0':'')+objPreferences['lFileNumber'];
  104.                                 objPreferences['lFileNumber']++;
  105.                                 Registry_SetKeyValue(HKCU, RegistryInit(), 'lFileNumber', objPreferences['lFileNumber'], REG_DWORD);
  106.                         }
  107.                 }
  108.                 sFile = sFile.replace(/!(time24|time)/gi, this.GetTime() );
  109.                 sFile = sFile.replace(/!date/gi, this.GetDate() );
  110.                 sFile = sFile.replace(/!email/gi, Messenger.MyEmail);
  111.                
  112.                 return (bOverlayText?sFile:sFile.replace(/[\\/:*>""<>\|]/g, ''));
  113.         },
  114.        
  115.         /*
  116.                 Name:   GetDate
  117.                 Purpose:        Get the current date in the users locale
  118.                 Parameters:     None
  119.                 Return: The current date in string format
  120.         */
  121.         "GetDate" : function () {
  122.                 var SYSTEMTIME = Interop.ALlocate(16);
  123.                 var sDate = Interop.Allocate(512);
  124.                 Interop.Call('kernel32', 'GetSystemTime', SYSTEMTIME);
  125.                 Interop.Call('kernel32', 'GetDateFormatW', 0x400 /* LOCALE_USER_DEFAULT */, 0, SYSTEMTIME, 0, sDate, 512);
  126.                 return sDate.ReadString(0);
  127.         },
  128.        
  129.         /*
  130.                 Name:   GetTime
  131.                 Purpose:        Get the current time in the users locale
  132.                 Parameters:     None
  133.                 Return: The current time im string format
  134.         */
  135.         "GetTime" : function () {
  136.                 var SYSTEMTIME = Interop.ALlocate(16);
  137.                 var sTime = Interop.Allocate(512);
  138.                 Interop.Call('kernel32', 'GetLocalTime', SYSTEMTIME);
  139.                 Interop.Call('kernel32', 'GetTimeFormatW', 0x800 /* LOCALE_USER_DEFAULT */, 0, SYSTEMTIME, 0, sTime, 512);
  140.                 return sTime.ReadString(0);
  141.         },
  142.        
  143.         /*
  144.                 Name:   DeleteSessionImages
  145.                 Purpose:        Deletes the images created in the users session
  146.                 Parameters:     None
  147.                 Return: None
  148.         */
  149.         "DeleteSessionImages" : function () {
  150.                 if (objPreferences['cDeleteSessionImages'] === 1) {
  151.                         for (var j in this.SessionImages.Images) Interop.Call('kernel32', 'DeleteFileW', this.SessionImages.Images[j]);
  152.                 }
  153.         },
  154.        
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.         "GetFilename" : function (s) {
  162.                 var regex = /.*\\([^\\]+)$/;
  163.                 try {
  164.                         return regex.exec(s)[1];
  165.                 } catch (e) {
  166.                         return s;
  167.                 }
  168.         },
  169.        
  170.         /*
  171.                 Name:   GetExtension
  172.                 Purpose:        Get the extension of the passed string
  173.                 Parameters:     s - The string to find the extension of
  174.                 Return: The extension of the file
  175.         */
  176.         "GetExtension" : function (s) {
  177.                 var regex = /\.([^\.]+)$/;
  178.                 try {
  179.                         return regex.exec(s)[1];
  180.                 } catch (e) {
  181.                         return s;
  182.                 }
  183.         }
  184. }

Version

  • 5.0.0070_20100325_publicbeta1

Developers

Project Details

  • Folders8
  • Files122
  • Total Lines11,867
  • Repository Version70

User Count

  • 162