WixSharp - Specifying order for a ManageAction to run when there are multiple - action

I've been using ManagedActionand and ElevatedManagedAction for sometime and everything has been great; however, I have a need now to execute actions in a particular order, or at least ensure actions are done first/last as may be necessary.
I assumed that actions were executed in the order entered for example:
Project project =
new Project("My Project",
new Property("SOME_PROPERTY", "ABC"),
new Dir(#"%ProgramFiles%\blah blah blah",
new File(...),
...
new ManagedAction(CustomActions.FirstAction, ...) {},
...
new ManagedAction(CustomActions.LastAction, ...) {}
...
I have a number of actions and so then thought, well ... , maybe bottom up, so I put what I wanted to run first at the bottom. That didn't change the order, so then I thought maybe alphabetical and did a couple of tests and sure enough that's what it did.
So, is there another way to specify the order actions are called other than adding a prefix for the name of the action, like A01_FirstAction, A02_LastAction ...?
Thanks,
Rick

Yes there is!
project.Actions = new WixSharp.Action[] {
new ManagedAction(CustomActions.MyFirstCustomAction,Return.check, When.Before, Step.InstallFinalize, Condition.NOT_Installed),
new ManagedAction(CustomActions.MySecondCustomAction,Return.check, When.After, Step.PreviousAction, Condition.NOT_Installed),
new ManagedAction(CustomActions.MyThirdCustomAction,Return.check, When.After, Step.PreviousAction, Condition.NOT_Installed)
}
Just take a look at the 2 parameters When and Step. In this case the first ManagedAction will be executed Before the step InstallFinalize. The second ManagedAction will be executed After the PreviousAction. This means after the previous action defined in the array. Same goes with the last ManagedAction. That's the way I figured out to specify an order.
Hope this helps.

Related

How to check for existence of object in Roblox with lua?

I am trying to code a gui that is dynamically assigned. I have four teams. I am getting stuck at a certain point. I want to make a function that, when a player joins the game, checks if the other teams have already scored to update their labels. It looks like this:
local function updateAllLabelsLateArrival(redPoints, bluePoints, yellowPoints, greenPoints)
game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam.Points.Text = redPoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyBlueTeam.Points.Text = bluePoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.NewYellerTeam.Points.Text = yellowPoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.LimeGreenTeam.Points.Text = greenPoints
end
The function is remotely triggered from a server-side script when a player joins. The problem I have is that not all four labels might exist. Suppose a green team player joins in when there is only a red team player already playing. It will come back with the error
ReallyBlueTeam is not a valid member of ScreenGui
I thought wrapping each line in an if statement to check if the label exists, like so:
if game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam then game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam.Points.Text = redPoints end
But this is giving the same error. So my question is, how do I check that a label has been created before updating the points? thanks
Assuming this is a localcsript, you can use WaitForChild() which will yield until the label has been created!
game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("ReallyRedTeam"):WaitForChild("Points").Text = redPoints
More information about WaitForChild here!
Alternatively, if you don't know for definite they will be created, you can use FindFirstChild. This won't yield.
if game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild("ReallyRedTeam") then
print("it exists")
end
More information about FindFirstChild here!
Hope that helps!
If you want them all on one line each then the best to use would be FindFirstChild() as #jjwood1600 has said. I would also recommend making use of a variable to shorten your GUI paths as you can see below:
local function updateAllLabelsLateArrival(redPoints, bluePoints, yellowPoints, greenPoints)
local userGui = game.Players.LocalPlayer.PlayerGui.ScreenGui
if userGui:FindFirstChild("ReallyRedTeam") then userGui.ReallyRedTeam.Points.Text = redPoints end
if userGui:FindFirstChild("ReallyBlueTeam") then userGui.ReallyBlueTeam.Points.Text = bluePoints end
if userGui:FindFirstChild("NewYellerTeam") then userGui.NewYellerTeam.Points.Text = yellowPoints end
if userGui:FindFirstChild("LimeGreenTeam") then userGui.LimeGreenTeam.Points.Text = greenPoints end
end
In normal Lua you can indeed do the if statements the way you did where you don't use FindFirstChild but Roblox's own version RBX.Lua doesn't.

QUndoStack remove specific command

How can I remove a specific command from a QUndoStack?
This command can be given by its index or pointer.
If you are using Qt 5.9, the QUndoStack::command(int index) and QUndoCommand::setObsolete(bool obsolete) functions are probably what you are looking for. The relevant docs from the QUndoStack::redo() command provide the explanation for how an obsoleted command is handled:
If QUndoCommand::isObsolete() returns true for the current command, then the command will be deleted from the stack. Additionally, if the clean index is greater than or equal to the current command index, then the clean index is reset.
That's the thing about stacks - you only work on top of the stack. You can push and you can pop. You don't remove stuff from the middle of the stack.
In an undo-redo scenario this is even more important, as the order of commands must be diligently preserved for the whole thing to work. Otherwise you will break it.
Which is why it is called an "undo stack" and not "reverse arbitrary action whatchamacallit".
There is QUndoStack::setIndex(int idx) which will undo all commands until the provided index. But you cannot really remove only a specific command. You need to undo all commands until you reach and remove the one you want.
As #dtech has pointed out, it does not make sense to undo a command which is not at the most recently pushed command (i.e., the command at top of the stack).
It does, however, make sense to undo the most recently pushed command.
And QUndoStack provides a very convenient way to do this: QUndoStack::undo().
But, this does not delete the command, as it will still be available through QUndoStack::push(...). To truly delete the command, it must be marked obsolete before undoing it:
auto* cmd = const_cast<QUndoCommand*>(undo_stack.command(undo_stack.count()-1));
cmd->undo(); // must be called explicitly
cmd->setObsolete(true);
undo_stack.undo();
It requires a const_cast, so I'd call it a hack. But for me, it works.

reverse() on spawns in cocos2dx

I am reading doc of cocos2dx on Actions (link: http://www.cocos2d-x.org/wiki/Actions). They mention reverse function on sequences and spawns at the bottom.
I am just a little confused what difference would reverse make on spawns, since according to what I understand spawns in cocos2d corporate actions together and make them happen at the same time? If this is true reverse would make almost no variations to spawns, at least visually? There is one (potential) line of explanation in the doc says "However it is not just
simply running in reverse. It is actually manipulating the properties of the original Sequence or Spawn in reverse too." Is it because of this "properties" that there is really some difference, probably somewhere in bottom level? Can someone explain this?
I don't think Spawn::reverse() is special. One thing I like Cocos2d-x is that I can see the source code by clicking F12.
Spawn* Spawn::reverse() const
{
return Spawn::createWithTwoActions(_one->reverse(), _two->reverse());
}
//Definition of Spawn
Spawn{
//...
protected:
//FiniteTimeAction is a derived class of Action
FiniteTimeAction *_one;
FiniteTimeAction *_two;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Spawn);
};
Yes, the reverse will not make any visible visually as it will be reversing every action and there will be no movement.As I am giving an example of jumpBy and reversing the jumps of the sprite using a sequence.
auto jump = JumpBy::create(3,Vec2(100, 0),50,3);
auto jumpBack = jump->reverse();
sceneSprite->runAction(Sequence::create(jump,jumpBack, nullptr));

Cakephp 2.1 Router::connect /* except some actions

I would like to know whether it's possible to have something like this next line but with the exclusion of some actions. Because I would like to have manage, add, delete,... to go to the respective action and not to the display action. I know it's possible by specifying these rules explicitely upfront, but if you have quite some of these it will not look to good in the router file.
Router::connect('/paginas/manage', array('controller' => 'paginas', 'action' => 'manage'));
...
Router::connect('/paginas/*', array('controller' => 'paginas', 'action' => 'display'));
So the aim is to remove the first line...
Thanks.
Do something like this in your PaginasController which is basicly the PagesController I think.:
....
public function display(){
// Assuming default behavior of cakephp here
...
if (!empty($path[0])) {
$page = $path[0];
if(
method_exists($this, $page) &&
!in_array(
$page,
array(
// Methods that never should be executed in this controller are going in here
)
)
){
$this->{$page}();
}
}
}
This would execute a specific method in the controller. You could exit it there to make it stop working afterwards.
This might be a bit dangerous though because it can access parent methods of AppController, too.
The other way in which you also need exactly two of those Router::connect() rules one described here: http://api.cakephp.org/class/router#method-Routerconnect
Router::connect(
'paginas/:action/*',
array(),
array('paginas' => '(manage|add|delete)')
);
This one goes first followed by the other one. Never tested!
Though I don't see why there should be public methods for editing pages. Use these to seperate them from the rest: http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing
I recommend, if you are trying to do this what I am thinking of, that you won't start to write a management for pages using the PagesController. "Pages" is a more or less reserved word in cake and you can get in big trouble with using those words (wrote a "File" plugin once including a "File" model. Waste of time as if since cake1.2 or 1.3 there is actually a "File" class to handle file operations). Create something new like "ContentPage" or whatever for it. You are on a saver side then. This paragraph is maybe useless, because your controller is not even named "Pages", but I hate to delete long ones, so it stays, just in case you need this information once.
Also i recommend not to change programming language, which means, you either use english or spanish or whatever but not both or worst more. You could name your route whatever you want to, but the class names should maybe stay in english because cake is also.
Greetings
func0der

Changing the Total Number of Recent Files

I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:
http://www.codeproject.com/KB/menus/changemru.aspx
http://www.microsoft.com/msj/0899/c/c0899.aspx
It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:
void CMyWinApp::SetMRUListSize( int size )
{
// size guaranteed to be between 1 and 16
delete m_pRecentFileList ;
LoadStdProfileSettings( size ) ;
}
What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?
My CApp derives from CWinApp. In initInstance, you have this line:
LoadStdProfileSettings(10);
At the end of InitInstance, add this code:
m_pmf->m_pRecentFileList = m_pRecentFileList;
Here m_pmf is my MainFrame class and I created a member CMainFrame::m_pRecentFileList of type CRecentFileList which is in the MFC source file filelist.cpp. m_pRecentFileList on the right is protected and CMainFrame doesn't have access to it from outside InitInstance, but you can make a functional copy here.
At the end of CMainFrame::OnClose, force a registry update by:
m_pRecentFileList->WriteList();
// Force registry update on exit. This doesn't work without forcing.
I don't even have to rebuild m_pRecentFileList, the MRU mechanism updates it correctly. Example: 5 MRU items, the first is moved to another directory and can no longer be found. Stepping through the code in the debugger shows that the bad entry is removed from the list. For some reason, the updated list isn't saved correctly unless I force it as explained above. I originally thought the problem might have something to do with privileges (64-bit Win7), but running the app as admin didn't help.
Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.
Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:
m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
bReturn = TRUE;
// Reload list of MRU files from registry
m_pRecentFileList->ReadList();
}
[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?
There's another CodeProject example which might help too.