Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################################################
- # This software is open source, licensed under the GNU General Public
- # License, version 2.
- # Basically, this means that you're allowed to modify and distribute
- # this software. However, if you distribute modified versions, you MUST
- # also distribute the source code.
- # See http://www.gnu.org/licenses/gpl.html for the full license.
- #########################################################################
- # profiles selector (full)
- # d3fc0n 30/12/2007
- #########################################################################
- package executionProfileChange;
- use strict;
- use File::Spec;
- use Plugins qw(load getFilesFromDirs);
- use Globals qw($interface $quit);
- Plugins::register('executionProfileChange', 'executionProfileChange', \&Unload);
- my $hooks = Plugins::addHooks(
- ['start', \&onStart]
- );
- my $chooks = Commands::register(
- ['changeProfile', "Changes profile", \&commandHandler]
- );
- my $baseControlFolder;
- my $pluginFolderInControl;
- my $pluginConfigFile;
- my %eventProfiles;
- my %profileList;
- my $currentProfile;
- # onUnload
- sub Unload {
- Plugins::delHooks($hooks);
- Commands::unregister($chooks);
- }
- sub onStart {
- $baseControlFolder = $Settings::controlFolders[0];
- $pluginFolderInControl = $baseControlFolder.'\profiles';
- $pluginConfigFile = $pluginFolderInControl.'\pluginConf.txt';
- my $openblock = 0;
- open my $conf, "<:utf8", $pluginConfigFile;
- while (<$conf>) {
- $. == 1 && s/^\x{FEFF}//;
- s/(.*)[\s\t]+#.*$/$1/;
- s/^\s*#.*$//;
- s/^\s*//;
- s/\s*[\r\n]?$//g;
- s/ +/ /g;
- next unless ($_);
- if (/^startingProfile\s+(\w+)$/i) {
- $currentProfile = $1;
- } elsif (/^eventProfiles\s+{$/i) {
- $openblock = 1;
- } elsif ($openblock) {
- if (/^(\w+)\s+(\w+)$/i) {
- $eventProfiles{$1} = $2;
- } elsif (/^}$/) {
- $openblock = 0;
- } else {
- $quit = 1;
- }
- }
- }
- close($conf);
- unless (defined $currentProfile) {
- $quit = 1;
- return;
- }
- opendir my $d, $pluginFolderInControl;
- my @fileList = readdir($d);
- closedir $d;
- foreach (@fileList) {
- next unless -d File::Spec->catdir($pluginFolderInControl, $_);
- next if ($_ =~ /^\./);
- $profileList{$_} = 1;
- }
- unless (exists $profileList{$currentProfile}) {
- $quit = 1;
- return;
- }
- loadProfile($currentProfile, 1);
- }
- sub loadProfile {
- my ($newProfile, $load) = @_;
- if ($load) {
- unshift @Settings::controlFolders, File::Spec->catdir($pluginFolderInControl, $newProfile);
- } else {
- }
- #unshift @Settings::controlFolders, File::Spec->catdir($pluginFolderInControl, $startingProfile);
- #$quit = 1;
- #return;
- }
- sub commandHandler {
- }
- return 1;
Advertisement
Add Comment
Please, Sign In to add comment