Example #1
0
 private static function relocateShortcut()
 {
     $WshShell = new COM('WScript.Shell', null, CP_UTF8);
     $FSO = new COM('Scripting.FileSystemObject', null, CP_UTF8);
     $desktop = $WshShell->SpecialFolders('Desktop');
     $startmenu = $WshShell->SpecialFolders('Programs');
     $startmenu = $FSO->BuildPath($startmenu, utf8_encode('XAMPP for Windows'));
     $xampppath = utf8_encode(self::$xampppath);
     $links = array();
     $links[$FSO->BuildPath($desktop, utf8_encode('XAMPP Control Panel.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'Description' => utf8_encode('XAMPP Control Panel'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Control Panel.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'Description' => utf8_encode('XAMPP Control Panel'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Setup.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp_setup.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Setup'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Shell.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp_shell.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Shell'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Uninstall.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('uninstall_xampp.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Uninstall'));
     foreach ($links as $shortcut => $value) {
         if (!$FSO->FileExists($shortcut)) {
             continue;
         }
         try {
             $shortcut_file = $FSO->GetFile($shortcut);
             $oldfileperm = $shortcut_file->attributes;
             if (($oldfileperm & 1) == 1) {
                 $shortcut_file->attributes += -1;
             }
         } catch (Exception $e) {
             throw new XAMPPException('File \'' . utf8_decode($shortcut) . '\' is not writable.');
         }
         $ShellLink = $WshShell->CreateShortcut($shortcut);
         $ShellLink->TargetPath = $value['TargetPath'];
         $ShellLink->WorkingDirectory = $value['WorkingDirectory'];
         $ShellLink->WindowStyle = $value['WindowStyle'];
         $ShellLink->IconLocation = $value['IconLocation'];
         $ShellLink->Description = $value['Description'];
         $ShellLink->Save();
         $ShellLink = null;
         $shortcut_file->attributes = $oldfileperm;
         $shortcut_file = null;
     }
     $FSO = null;
     $WshShell = null;
     return;
 }
/**
 * Scan the location of the song to find valid cover art file
 * COM object must be used for unicode filenames
 *
 * @param string $path Absolute path of song location
 * @return string Absolute path of cover art file
 */
function getArtName(string $path) : string
{
    $art = "";
    //	Normalize $path
    if (substr($path, 0, -1) != DIRECTORY_SEPARATOR) {
        $path .= DIRECTORY_SEPARATOR;
    }
    //	Art files to search for
    $artNames = array("Folder", "Cover", "folder", "cover");
    $artExtensions = array(".jpg", ".png");
    try {
        $com = new COM("Scripting.FileSystemObject", null, CP_UTF8);
        //	Permute over art filenames
        foreach ($artNames as $name) {
            foreach ($artExtensions as $extension) {
                if ($com->FileExists($path . $name . $extension)) {
                    $art = $path . $name . $extension;
                    break;
                }
            }
        }
    } catch (Exception $e) {
        echo "Unable to search for art: " . $e->getMessage() . "\n";
    }
    $com = null;
    return $art;
}