Skip to content

Commit

Permalink
added a lot of scripts removed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiantheblind committed Aug 4, 2011
1 parent 8db35bd commit b36dc74
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 352 deletions.
253 changes: 2 additions & 251 deletions MPOLnchActionComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,13 @@ class MPOLnchActionComponent : public CActionComponent

void DoStoreFCQueries();

/** This copys the query files to the right preference folder */

void CopyQueryFilesToPrefsFolder(PMString fcfilename, PMString fctype);

void CopyFilesToLauncherFolder(PMString filename , PMString foldername, bool16 subfolder);


/** Encapsulates functionality for the AddItem menu item.
@param invokedWidget Widget that initiated the event (the panel menu), useful for getting the panel & other widgets.
*/
void DoAddItem(IPMUnknown *invokedWidget);


/* My personal copyFile
* until i get FileUtils::CopyFile() to work
*/
// bool copyFile (const char SRC[], const char DEST[]);


/** Encapsulates functionality for the RemoveItem menu item.
Expand Down Expand Up @@ -244,154 +233,10 @@ void MPOLnchActionComponent::DoAbout()
void MPOLnchActionComponent::DoStoreFCQueries()
{
MPOLnchHelper helper;

for (int i = 0; i < helper.FCGREPMAXITEMS ; i++) {

CopyQueryFilesToPrefsFolder(helper.GetGrepFCFile(i), PMString("GREP"));

// IDFile theGRPSource = helper.GetInternalResourceFolder();
//
// FileUtils::AppendPath(&theGRPSource, PMString(helper.GetGrepFCFile(i)));
// PMString grpFileStringUrl = FileUtils::SysFileToFileURL(theGRPSource);
// if(!FileUtils::DoesFileExist(theGRPSource)){
// CAlert::InformationAlert(" could not find the Source File. I am Here-> " + grpFileStringUrl
// +"\n"+
// " Please report this bug to: [email protected]");
// break;
// }
//
// // this gets the GREP folder within the Library/Preferences/Adobe InDesign/ ...
// IDFile theGRPTarget;
// FileUtils::GetAppRoamingDataFolder(&theGRPTarget, "Find-Change Queries");
// FileUtils::AppendPath(&theGRPTarget,"GREP");
// FileUtils::CreateFolderIfNeeded(theGRPTarget,kTrue);
// PMString fngrp(helper.GetGrepFCFile(i));
// FileUtils::AppendPath(&theGRPTarget, fngrp);
//
// if(!FileUtils::DoesFileExist(theGRPTarget)){
// CAlert::InformationAlert("I will try to copy "+fngrp+ " to your Preferences");
// if(!FileUtils::CopyFile(theGRPSource, theGRPTarget)){
// CAlert::InformationAlert("Could not copy "+fngrp+". Sorry");
// }
// }
//



} // end of for FCGREPMAXITEMS

for (int j = 0; j < helper.FCTEXTMAXITEMS ; j++) {

//IDFile theFCTXTSource = helper.GetInternalResourceFolder();
CopyQueryFilesToPrefsFolder(helper.GetTextFCFile(j), PMString("Text"));


} // end of for FCTEXTMAXITEMS

for (int k = 0; k < helper.FCOBJECTMAXITEMS ; k++) {

//IDFile theFCOBJSource = helper.GetInternalResourceFolder();
CopyQueryFilesToPrefsFolder(helper.GetObjectFCFile(k), PMString("Object"));

} // end of for FCGREPMAXITEMS
helper.RestoreFCQueries();

} // end of DoStoreFCQueries

/* A Helper For copying files
*/

void MPOLnchActionComponent::CopyQueryFilesToPrefsFolder(PMString fcfilename, PMString fctype){

MPOLnchHelper helper;

IDFile theGRPSource = helper.GetInternalResourceFolder();

FileUtils::AppendPath(&theGRPSource, fcfilename);
PMString grpFileStringUrl = FileUtils::SysFileToFileURL(theGRPSource);
if(!FileUtils::DoesFileExist(theGRPSource)){
CAlert::InformationAlert(" could not find the Source File. I am Here-> " + grpFileStringUrl
+"\n"+
" Please report this bug to: [email protected]");
return;
}

// this gets the GREP folder within the Library/Preferences/Adobe InDesign/ ...
IDFile theGRPTarget;
FileUtils::GetAppRoamingDataFolder(&theGRPTarget, "Find-Change Queries");
FileUtils::AppendPath(&theGRPTarget,fctype);
FileUtils::CreateFolderIfNeeded(theGRPTarget,kTrue);
PMString fngrp(fcfilename);
FileUtils::AppendPath(&theGRPTarget, fngrp);

if(!FileUtils::DoesFileExist(theGRPTarget)){
CAlert::InformationAlert("I will try to copy "+fngrp+ " to your Preferences");
if(!FileUtils::CopyFile(theGRPSource, theGRPTarget)){
CAlert::InformationAlert("Could not copy "+fngrp+". Sorry");
}
}
}

/* A Helper For copying files
*/


void MPOLnchActionComponent::CopyFilesToLauncherFolder(PMString filename , PMString foldername, bool16 subfolder){

MPOLnchHelper helper;

IDFile source = helper.GetInternalResourceFolder();

FileUtils::AppendPath(&source, filename);
PMString fileStringUrl = FileUtils::SysFileToFileURL(source);
if(!FileUtils::DoesFileExist(source)){
CAlert::InformationAlert(" could not find the Source File. I am Here-> " + fileStringUrl
+"\n"+
" Please report this bug to: [email protected]");
return;
}

IDFile target = helper.GetScriptFilesFolder();
if (subfolder) {

FileUtils::AppendPath(&target, foldername);
FileUtils::CreateFolderIfNeeded(target,kTrue);

}

PMString fn(filename);

FileUtils::AppendPath(&target, fn);

if(!FileUtils::DoesFileExist(target)){
if (subfolder) {
CAlert::InformationAlert("I will try to copy "+fn
+ " to the folder: Scripts Panel/MPO Launcher/"
+foldername);
}else{
CAlert::InformationAlert("I will try to copy "+fn
+ " to the folder: Scripts Panel/MPO Launcher");
}
if(!FileUtils::CopyFile(source, target)){
CAlert::InformationAlert("Could not copy "+fn
+". Sorry");
}
}

// this gets the GREP folder within the Library/Preferences/Adobe InDesign/ ...
// IDFile target;
// FileUtils::GetAppRoamingDataFolder(&target, "Find-Change Queries");
// FileUtils::AppendPath(&target,fctype);
// FileUtils::CreateFolderIfNeeded(target,kTrue);
// PMString fngrp(fcfilename);
// FileUtils::AppendPath(&theGRPTarget, fn);
//
// if(!FileUtils::DoesFileExist(target)){
// CAlert::InformationAlert("I will try to copy "+fn+ " to your Preferences");
// if(!FileUtils::CopyFile(source, target)){
// CAlert::InformationAlert("Could not copy "+fn+". Sorry");
// }
// }
}

/* DoAddItem
*/
Expand All @@ -400,102 +245,8 @@ void MPOLnchActionComponent::DoAddItem(IPMUnknown *invokedWidget)
// building the scripts

MPOLnchHelper helper;


for (int i = 0; i < helper.MAXITEMS ; i++) {
helper.RestoreMPOLnchScrpts();


// // the script files
// //
// //
// IDFile theSource = helper.GetInternalResourceFolder();//scriptfiles[i];
// FileUtils::AppendPath(&theSource, PMString(helper.GetScriptFile(i)));
// PMString sourceFileStringUrl = FileUtils::SysFileToFileURL(theSource);
// if(!FileUtils::DoesFileExist(theSource)){
// CAlert::InformationAlert(" could not find the Source File. I am Here-> " + sourceFileStringUrl
// +"\n"+
// " Please report this bug to: [email protected]");
// break;
// }
// IDFile theTarget = helper.GetScriptFilesFolder();
// PMString fn(helper.GetScriptFile(i));
//
// FileUtils::AppendPath(&theTarget, fn);
//
// if(!FileUtils::DoesFileExist(theTarget)){
// CAlert::InformationAlert("I will try to copy "+fn+ " to the folder: Scripts Panel/MPO Launcher");
// if(!FileUtils::CopyFile(theSource, theTarget)){
// CAlert::InformationAlert("Could not copy "+fn+". Sorry");
// }
// }

CopyFilesToLauncherFolder(helper.GetScriptFile(i) , "NOFOLDER",false);
CopyFilesToLauncherFolder(helper.GetHelpFile(i) , "help",true);

// the help files
//
//
//IDFile theHelpSource = helper.GetInternalResourceFolder();//scriptfiles[i];
//
//
// FileUtils::AppendPath(&theHelpSource, PMString(helper.GetHelpFile(i)));
//
// PMString sourceHelpFileStringUrl = FileUtils::SysFileToFileURL(theHelpSource);
//
// if(!FileUtils::DoesFileExist(theHelpSource)){
// CAlert::InformationAlert(" could not find the Help File. I am Here-> " + sourceHelpFileStringUrl
// +"\n"+
// " Please report this bug to: [email protected]");
// break;
// }
//
//
// IDFile theHelpTarget = helper.GetScriptFilesFolder();
// FileUtils::AppendPath(&theHelpTarget, PMString("help"));
// FileUtils::CreateFolderIfNeeded(theHelpTarget,kTrue);
// PMString fnh(helper.GetHelpFile(i));
// FileUtils::AppendPath(&theHelpTarget, fnh);
//
//
// if(!FileUtils::DoesFileExist(theHelpTarget)){
// CAlert::InformationAlert("I will try to copy "+fnh+ " to the folder: Scripts Panel/MPO Launcher/help");
// if(!FileUtils::CopyFile(theHelpSource, theHelpTarget)){
// CAlert::InformationAlert("Could not copy "+fnh+". Sorry");
// }
// }
}// end for MAXITEMS


//THE META FILES
//

for(int j = 0; j < helper.METAMAXITEMS; j++){

IDFile theMetaSource = helper.GetInternalResourceFolder();//scriptfiles[i];
FileUtils::AppendPath(&theMetaSource, PMString(helper.GetMetaFile(j)));

PMString metaSourceFileStringUrl = FileUtils::SysFileToFileURL(theMetaSource);

if(!FileUtils::DoesFileExist(theMetaSource)){
CAlert::InformationAlert(" could not find the Source File. I am Here-> " + metaSourceFileStringUrl
+"\n"+
" Please report this bug to: [email protected]");
break;
}
// this gets the MPO Launcher folder within the scripts panel
IDFile theMetaTarget = helper.GetScriptFilesFolder();
FileUtils::AppendPath(&theMetaTarget, PMString("meta"));
FileUtils::CreateFolderIfNeeded(theMetaTarget,kTrue);
PMString fnm(helper.GetMetaFile(j));
FileUtils::AppendPath(&theMetaTarget, fnm);
if(!FileUtils::DoesFileExist(theMetaTarget)){
CAlert::InformationAlert("I will try to copy "+fnm+ " to the folder: Scripts Panel/MPO Launcher/meta");
if(!FileUtils::CopyFile(theMetaSource, theMetaTarget)){
CAlert::InformationAlert("Could not copy "+fnm+". Sorry");
}
}

}

}

Expand Down
25 changes: 1 addition & 24 deletions MPOLnchEyeballObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,33 +196,17 @@ void MPOLnchEyeballObserver::Update

PMString nodeName(textControlData->GetString());

// Show it only for debug
//nodeName.SetTranslatable(kFalse); // only for debug- not real code
//CAlert::InformationAlert(nodeName);
MPOLnchHelper helper;
IDFile scriptFile = helper.GetScriptFilesFolder();

//FileUtils::GetAppInstallationFolder(&scriptFile); //application folder path
// FileUtils::AppendPath(&scriptFile, PMString("Scripts"));
// FileUtils::AppendPath(&scriptFile, PMString("Scripts Panel"));
// FileUtils::AppendPath(&scriptFile, PMString("MPO Launcher"));

PMString fn(nodeName);
PMString ext(".jsx");


FileUtils::AppendPath(&scriptFile, fn + ext);






if (FileUtils::DoesFileExist(scriptFile)) {




// for debug
//FileUtils::OpenFile(scriptFile);
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));
Expand All @@ -239,17 +223,10 @@ void MPOLnchEyeballObserver::Update
scriptRunner->RunFile(scriptFile,scriptParams);
}// close filestatus
}else {
CAlert::InformationAlert("Got an error. You need the MPO Launcher Scripts Folder in the Scripts Panel");
CAlert::InformationAlert(helper.MissingScrptFileStr(nodeName));
}




// PMString dbgInfoString("MPOLnchEyeballObserver::Update() ");
// dbgInfoString.SetTranslatable(kFalse); // only for debug- not real code
// CAlert::InformationAlert(dbgInfoString);


} while(0);
}

Expand Down
Loading

0 comments on commit b36dc74

Please sign in to comment.