Henrybk

Profilechanger

Feb 17th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.71 KB | None | 0 0
  1. #########################################################################
  2. # This software is open source, licensed under the GNU General Public
  3. # License, version 2.
  4. # Basically, this means that you're allowed to modify and distribute
  5. # this software. However, if you distribute modified versions, you MUST
  6. # also distribute the source code.
  7. # See http://www.gnu.org/licenses/gpl.html for the full license.
  8. #########################################################################
  9. # profiles selector (full)
  10. # d3fc0n 30/12/2007
  11. #########################################################################
  12.  
  13. package executionProfileChange;
  14.  
  15. use strict;
  16. use File::Spec;
  17. use Plugins qw(load getFilesFromDirs);
  18. use Globals qw($interface $quit);
  19.  
  20. Plugins::register('executionProfileChange', 'executionProfileChange', \&Unload);
  21.  
  22. my $hooks = Plugins::addHooks(
  23.       ['start', \&onStart]
  24.    );
  25.  
  26. my $chooks = Commands::register(
  27.     ['changeProfile', "Changes profile", \&commandHandler]
  28. );
  29.  
  30. my $baseControlFolder;
  31. my $pluginFolderInControl;
  32. my $pluginConfigFile;
  33.  
  34. my %eventProfiles;
  35. my %profileList;
  36.  
  37. my $currentProfile;
  38.  
  39. # onUnload
  40. sub Unload {
  41.     Plugins::delHooks($hooks);
  42.     Commands::unregister($chooks);
  43. }
  44.  
  45. sub onStart {
  46.     $baseControlFolder = $Settings::controlFolders[0];
  47.     $pluginFolderInControl = $baseControlFolder.'\profiles';
  48.     $pluginConfigFile = $pluginFolderInControl.'\pluginConf.txt';
  49.    
  50.     my $openblock = 0;
  51.     open my $conf, "<:utf8", $pluginConfigFile;
  52.     while (<$conf>) {
  53.         $. == 1 && s/^\x{FEFF}//;
  54.             s/(.*)[\s\t]+#.*$/$1/;
  55.             s/^\s*#.*$//;
  56.             s/^\s*//;
  57.             s/\s*[\r\n]?$//g;
  58.             s/  +/ /g;
  59.             next unless ($_);
  60.             if (/^startingProfile\s+(\w+)$/i) {
  61.                 $currentProfile = $1;
  62.             } elsif (/^eventProfiles\s+{$/i) {
  63.                 $openblock = 1;
  64.             } elsif ($openblock) {
  65.                 if (/^(\w+)\s+(\w+)$/i) {
  66.                     $eventProfiles{$1} = $2;
  67.                 } elsif (/^}$/) {
  68.                     $openblock = 0;
  69.                 } else {
  70.                     $quit = 1;
  71.                 }
  72.             }
  73.     }
  74.     close($conf);
  75.    
  76.     unless (defined $currentProfile) {
  77.          $quit = 1;
  78.          return;
  79.     }
  80.    
  81.     opendir my $d, $pluginFolderInControl;
  82.     my @fileList = readdir($d);
  83.     closedir $d;
  84.    
  85.     foreach (@fileList) {
  86.         next unless -d File::Spec->catdir($pluginFolderInControl, $_);
  87.         next if ($_ =~ /^\./);
  88.         $profileList{$_} = 1;
  89.     }
  90.    
  91.     unless (exists $profileList{$currentProfile}) {
  92.         $quit = 1;
  93.         return;
  94.     }
  95.    
  96.     loadProfile($currentProfile, 1);
  97. }
  98.  
  99. sub loadProfile {
  100.     my ($newProfile, $load) = @_;
  101.     if ($load) {
  102.         unshift @Settings::controlFolders, File::Spec->catdir($pluginFolderInControl, $newProfile);
  103.     } else {
  104.        
  105.     }
  106.     #unshift @Settings::controlFolders, File::Spec->catdir($pluginFolderInControl, $startingProfile);
  107.     #$quit = 1;
  108.     #return;
  109. }
  110.  
  111. sub commandHandler {
  112.    
  113. }
  114.  
  115. return 1;
Advertisement
Add Comment
Please, Sign In to add comment