Skip to content

Commit f30aa09

Browse files
committed
Various bugfixes and code formatting
1 parent 04e38bd commit f30aa09

14 files changed

+66
-104
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This command will import a properly formatted YAML or JSON file as the given use
4343
| in | The path to the config file to import. |
4444
| out | The path to save the config file to, after import. Defaults to `/Users/XXX/Library/Prefer/dock.yml` | user | The user to import a dock for. This defaults to the current user, which makes it important to include this flag when running this tool as root.|
4545

46-
The format of the configuration is an array, with each primary key being separated by a spacer in the dock. Elements within the primary keys are entries in the dock. Each element is either an application's name, the an absolute path to an application, or an array describing a link to another resource. An example in YAML is below:
46+
The format of the configuration is an array, with each primary key being separated by a spacer in the dock. Elements within the primary keys are entries in the dock. Each element is either an application's name, an absolute path to an application, or an array describing a link to another resource. An example in YAML is below:
4747

4848
group1: - Messages - Postbox group2: - Safari - Firefox - 'Google Chrome' - 'Microsoft Edge' group5: - Hyper - { link: /Applications/Custom.terminal } - screen_sharing group6: - { link: /Applications/, section: others, display: folder, view: grid, sort: name } When processing application names, the following locations are checked for the application:
4949

@@ -54,7 +54,7 @@ When processing links, the following keys and values can be used:
5454

5555
|Key | Possible Values |
5656
|--|--|
57-
| link | A typical link with scheme (IE - file://) |
57+
| link | A typical link with a scheme (IE - file://) |
5858
| section | _apps_, _others_ |
5959
| display | _stack_, _folder_ |
6060
| view | _grid_, _fan_, _list_, _auto_ |
@@ -69,12 +69,12 @@ For all of these commands, the application name should be provided in lowercase,
6969
#### adobe:info _app_ _year_
7070
Provides information about an installed Adobe Creative Cloud application, output in JSON format. This information includes:
7171

72-
- Actual version installed
72+
- Version installed
7373
- Path to application
7474
- SAP code
7575
- Base version
7676
- Uninstaller command string
77-
- Paths to known preferences
77+
- Paths to known preferences
7878

7979
The year is optional for the applications that do not use it, such as XD, Dimension, and Lightroom.
8080

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ $command[] = new Command\AdobeInfoCommand();
1616
$command[] = new Command\AdobeBackupCommand();
1717
$command[] = new Command\AdobeTransferCommand();
1818
$command[] = new Command\MenuAddCommand();
19-
$app = new Application('MacPrefer', 'v1.3.1');
19+
$app = new Application('MacPrefer', 'v1.3.2');
2020
$app->addCommands($command);
2121
$app->run();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"email": "aaron@jonesicoding.com"
1515
}
1616
],
17-
"version": "1.3.1",
17+
"version": "1.3.2",
1818
"require": {
1919
"ext-json": "*",
2020
"ext-posix": "*",

dist/prefer.phar

-689 Bytes
Binary file not shown.
Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace DevCoding\Mac\Command;
54

6-
75
use DevCoding\Mac\Objects\CreativeCloudApp;
86

97
class AbstractAdobeConsole extends AbstractMacConsole
@@ -28,11 +26,11 @@ protected function getBackupPath($app, $year = null)
2826
{
2927
if ($year)
3028
{
31-
return sprintf("%s/Preferences/Prefer/CC/%s/%s", $this->getUser()->getLibrary(), $app, $year);
29+
return sprintf('%s/Preferences/Prefer/CC/%s/%s', $this->getUser()->getLibrary(), $app, $year);
3230
}
3331
else
3432
{
35-
return sprintf("%s/Preferences/Prefer/CC/%s", $this->getUser()->getLibrary(), $app);
33+
return sprintf('%s/Preferences/Prefer/CC/%s', $this->getUser()->getLibrary(), $app);
3634
}
3735
}
3836

@@ -44,7 +42,7 @@ protected function getBackupPath($app, $year = null)
4442
*/
4543
protected function doPreferenceBackup(CreativeCloudApp $ccApp, $dest)
4644
{
47-
$dest = $dest . '/tmp';
45+
$dest = $dest.'/tmp';
4846
if (!is_dir($dest))
4947
{
5048
if (!file_exists($dest))
@@ -58,28 +56,28 @@ protected function doPreferenceBackup(CreativeCloudApp $ccApp, $dest)
5856
}
5957

6058
$userDir = $this->getUser()->getDir();
61-
foreach($ccApp->getPreferences() as $preference)
59+
foreach ($ccApp->getPreferences() as $preference)
6260
{
63-
$path = sprintf("%s/%s", $userDir, $preference);
61+
$path = sprintf('%s/%s', $userDir, $preference);
6462
if (file_exists($path))
6563
{
66-
$cmd = sprintf('rsync -aP --ignore-times "%s" "%s/"',$path,$dest);
67-
exec($cmd,$output,$retval);
68-
if ($retval !== 0)
64+
$cmd = sprintf('rsync -aP --ignore-times "%s" "%s/"', $path, $dest);
65+
exec($cmd, $output, $retval);
66+
if (0 !== $retval)
6967
{
7068
throw new \Exception('An error was encountered backing up preferences: ');
7169
}
7270
}
7371
}
7472

75-
$date = date( 'Ymd-Hi' );
76-
$zipFile = sprintf( 'backup-%s.zip', $date );
77-
$zipPath = dirname($dest) . '/' . $zipFile;
78-
$cmd = sprintf( 'cd "%s" && zip -r "%s" ./* && cd -', $dest, $zipPath );
79-
exec( $cmd,$output, $retval );
80-
if( $retval || !file_exists( $zipPath ) )
73+
$date = date('Ymd-Hi');
74+
$zipFile = sprintf('backup-%s.zip', $date);
75+
$zipPath = dirname($dest).'/'.$zipFile;
76+
$cmd = sprintf('cd "%s" && zip -r "%s" ./* && cd -', $dest, $zipPath);
77+
exec($cmd, $output, $retval);
78+
if ($retval || !file_exists($zipPath))
8179
{
82-
throw new \Exception( "Could not compress the backup after copying." );
80+
throw new \Exception('Could not compress the backup after copying.');
8381
}
8482
else
8583
{
@@ -88,39 +86,4 @@ protected function doPreferenceBackup(CreativeCloudApp $ccApp, $dest)
8886

8987
return true;
9088
}
91-
92-
private function rcopy( $src, $dst )
93-
{
94-
if (!is_dir($dst))
95-
{
96-
@mkdir( $dst );
97-
}
98-
99-
if (is_dir($src))
100-
{
101-
$dir = opendir( $src );
102-
while( false !== ( $file = readdir( $dir ) ) )
103-
{
104-
if( ( $file != '.' ) && ( $file != '..' ) )
105-
{
106-
if( is_dir( $src . '/' . $file ) )
107-
{
108-
$this->rcopy( $src . '/' . $file, $dst . '/' . $file );
109-
}
110-
else
111-
{
112-
if( !copy( $src . '/' . $file, $dst . '/' . $file ) )
113-
{
114-
throw new \Exception( "Could not copy\n" . $src . "\nto\n" . $dst );
115-
}
116-
}
117-
}
118-
}
119-
closedir( $dir );
120-
}
121-
elseif(is_file($src))
122-
{
123-
copy($src, $dst.'/');
124-
}
125-
}
126-
}
89+
}

src/Command/AbstractPreferConsole.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace DevCoding\Mac\Command;
77

8-
use Symfony\Component\Console\Input\InputInterface;
98
use Symfony\Component\Yaml\Yaml;
109

1110
/**

src/Command/AdobeBackupCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace DevCoding\Mac\Command;
54

6-
75
use Symfony\Component\Console\Input\InputArgument;
86
use Symfony\Component\Console\Input\InputInterface;
97
use Symfony\Component\Console\Output\OutputInterface;
@@ -22,7 +20,7 @@ public function configure()
2220

2321
public function execute(InputInterface $input, OutputInterface $output)
2422
{
25-
$app = strtolower(str_replace(" ", "-", $this->io()->getArgument('application')));
23+
$app = strtolower(str_replace(' ', '-', $this->io()->getArgument('application')));
2624
$year = $this->io()->getArgument('year');
2725
$ccApp = $this->getCreativeCloudApp($app, $year);
2826
$this->io()->blankln();
@@ -34,11 +32,11 @@ public function execute(InputInterface $input, OutputInterface $output)
3432

3533
try
3634
{
37-
$this->io()->msg('Backing Up '.$ccApp->getFullName().' Preferences',50);
35+
$this->io()->msg('Backing Up '.$ccApp->getFullName().' Preferences', 50);
3836
$this->doPreferenceBackup($ccApp, $this->getBackupPath($app, $year));
3937
$this->io()->successln('[DONE]');
4038
}
41-
catch(\Exception $e)
39+
catch (\Exception $e)
4240
{
4341
$this->io()->errorln('[ERROR]');
4442
$this->io()->errorblk($e->getMessage());
@@ -57,4 +55,4 @@ public function execute(InputInterface $input, OutputInterface $output)
5755

5856
return self::EXIT_SUCCESS;
5957
}
60-
}
58+
}

src/Command/AdobeInfoCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace DevCoding\Mac\Command;
54

6-
75
use Symfony\Component\Console\Input\InputArgument;
86
use Symfony\Component\Console\Input\InputInterface;
97
use Symfony\Component\Console\Output\OutputInterface;
@@ -25,19 +23,19 @@ public function configure()
2523

2624
public function execute(InputInterface $input, OutputInterface $output)
2725
{
28-
$app = strtolower(str_replace(" ", "-", $this->io()->getArgument('application')));
29-
$year = $this->io()->getArgument('year');
26+
$app = strtolower(str_replace(' ', '-', $this->io()->getArgument('application')));
27+
$year = $this->io()->getArgument('year');
3028
$ccApp = $this->getCreativeCloudApp($app, $year);
3129

3230
if ($ccApp->getPath())
3331
{
34-
$this->io()->writeln(json_encode($ccApp, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES));
32+
$this->io()->writeln(json_encode($ccApp, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES));
3533
}
3634
else
3735
{
38-
echo "{}";
36+
echo '{}';
3937
}
4038

4139
return self::EXIT_SUCCESS;
4240
}
43-
}
41+
}

src/Command/AdobeTransferCommand.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3+
/** @noinspection PhpUnusedParameterInspection */
34

45
namespace DevCoding\Mac\Command;
56

6-
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Input\InputOption;
@@ -56,7 +56,7 @@ public function interact(InputInterface $input, OutputInterface $output)
5656

5757
if ($from = $this->io()->ask('What year should we copy preferences FROM?', $default))
5858
{
59-
$this->io()->getInput()->setOption('from',$from);
59+
$this->io()->getInput()->setOption('from', $from);
6060
}
6161
}
6262

@@ -73,7 +73,7 @@ public function validate(InputInterface $input, OutputInterface $output)
7373
{
7474
if ($from = $input->getOption('from'))
7575
{
76-
if (!is_numeric($from) || (int)$from < 2015)
76+
if (!is_numeric($from) || (int) $from < 2015)
7777
{
7878
throw new \Exception('You must use a year greater than 2015 for the "--from" option.');
7979
}
@@ -85,7 +85,7 @@ public function validate(InputInterface $input, OutputInterface $output)
8585

8686
if ($to = $input->getOption('to'))
8787
{
88-
if (!is_numeric($to) || (int)$to < 2015)
88+
if (!is_numeric($to) || (int) $to < 2015)
8989
{
9090
throw new \Exception('You must use a year greater than 2015 for the "--from" option.');
9191
}
@@ -95,7 +95,7 @@ public function validate(InputInterface $input, OutputInterface $output)
9595
throw new \Exception('You must use the "--from" option to indicate the year to copy preferences from.');
9696
}
9797

98-
if ((int)$from == (int)$to)
98+
if ((int) $from == (int) $to)
9999
{
100100
throw new \Exception('You must indicate a different year for the "--from" and "--to" options.');
101101
}
@@ -107,7 +107,7 @@ public function execute(InputInterface $input, OutputInterface $output)
107107
{
108108
$this->validate($input, $output);
109109
}
110-
catch(\Exception $e)
110+
catch (\Exception $e)
111111
{
112112
$this->io()->errorblk($e->getMessage());
113113

@@ -203,7 +203,7 @@ public function execute(InputInterface $input, OutputInterface $output)
203203
{
204204
$this->doPreferenceBackup($dst, $this->getBackupPath($app, $to));
205205
}
206-
catch(\Exception $e)
206+
catch (\Exception $e)
207207
{
208208
$this->io()->errorln('[ERROR]');
209209

@@ -214,12 +214,12 @@ public function execute(InputInterface $input, OutputInterface $output)
214214
$this->io()->successln('[DONE]');
215215

216216
// Copy Preferences
217-
$this->io()->msg(sprintf('Copying %s Prefs from %s to %s', $srcName, $from, $to),50);
217+
$this->io()->msg(sprintf('Copying %s Prefs from %s to %s', $srcName, $from, $to), 50);
218218
try
219219
{
220220
$this->copyPreferences($srcPrefs, $search, $replace);
221221
}
222-
catch(\Exception $e)
222+
catch (\Exception $e)
223223
{
224224
$this->io()->errorln('[ERROR]');
225225

@@ -242,11 +242,11 @@ public function execute(InputInterface $input, OutputInterface $output)
242242
protected function copyPreferences($srcPrefs, $search, $replace)
243243
{
244244
$uDir = $this->getUser()->getDir();
245-
foreach($srcPrefs as $srcPref)
245+
foreach ($srcPrefs as $srcPref)
246246
{
247247
$dstPref = str_replace($search, $replace, $srcPref);
248-
$srcPath = sprintf("%s/%s", $uDir, $srcPref);
249-
$dstPath = sprintf("%s/%s", $uDir, $dstPref);
248+
$srcPath = sprintf('%s/%s', $uDir, $srcPref);
249+
$dstPath = sprintf('%s/%s', $uDir, $dstPref);
250250

251251
if (file_exists($srcPath))
252252
{
@@ -262,16 +262,19 @@ protected function copyPreferences($srcPrefs, $search, $replace)
262262
}
263263

264264
$cmd = sprintf('rsync -aP --ignore-times "%s/" "%s/"', $srcPath, $dstPath);
265-
exec($cmd,$output,$retval);
265+
exec($cmd, $output, $retval);
266266

267-
if ($retval !== 0)
267+
if (0 !== $retval)
268268
{
269-
throw new \Exception(sprintf('An error was encountered copying preference directory "%s"', implode("\n",$output)));
269+
throw new \Exception(sprintf('An error was encountered copying preference directory "%s"', implode("\n", $output)));
270270
}
271271
}
272-
elseif(is_file($srcPath))
272+
elseif (is_file($srcPath))
273273
{
274-
if(is_file($dstPref)) { unlink($dstPath); }
274+
if (is_file($dstPref))
275+
{
276+
unlink($dstPath);
277+
}
275278
if (!copy($srcPath, $dstPath))
276279
{
277280
throw new \Exception(sprintf('An error was encountered copying %s', $srcPath));
@@ -285,13 +288,13 @@ protected function copyPreferences($srcPrefs, $search, $replace)
285288
chown($dstPath, $owner['name']);
286289
chgrp($dstPath, $group['name']);
287290
}
288-
catch(\Exception $e)
291+
catch (\Exception $e)
289292
{
290-
throw new \Exception(sprintf('An error was encountered setting permissions on "%s"',$dstPath));
293+
throw new \Exception(sprintf('An error was encountered setting permissions on "%s"', $dstPath));
291294
}
292295
}
293296
}
294297
}
295298
}
296299
}
297-
}
300+
}

src/Command/DockDumpCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
3737
// Get PList Source
3838
if (!$source = $input->getOption(self::INPUT))
3939
{
40-
$source = sprintf('%s/Preferences/com.apple.dock.plist', $this->getUserLibraryDir());
40+
$source = sprintf('%s/Preferences/com.apple.dock.plist', $this->getUser()->getLibrary());
4141

4242
if (file_exists($source))
4343
{

0 commit comments

Comments
 (0)