How to view complete contents of NSUserDefaults [duplicate] - objective-c

This question already has answers here:
See NSUserDefaults file content
(4 answers)
Closed 8 years ago.
I have an app where I store all of the user preferences in NSUserDefaults. I would like to be able to see (for debugging purposes) the complete contents of the NSUserDefaults file.
Can it be done without providing each of the keys?

Can it be done without providing each of the keys?
You can use dictionaryRepresentation of NSUserDefaults like that below example:-
NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
[def setObject:#"test1" forKey:#"test1"];
[def setObject:#"test2" forKey:#"test2"];
NSLog(#"%#",[[NSUserDefaults standardUserDefaults]dictionaryRepresentation]);
EDIT:-
When use dictionaryRepresentation it will print the complete information of user default, including extra value which is added in the defaults.
Below is the output of above code. Also you can see the value in the last which is extra included in the user defaults :-
AppleAntiAliasingThreshold = 4;
AppleGCIdleTimeInterval = "1.0";
AppleLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
AppleLocale = "en_US";
AppleMeasurementUnits = Inches;
AppleMetricUnits = 0;
AppleMiniaturizeOnDoubleClick = 0;
AppleShowScrollBars = Always;
AppleTextDirection = 0;
AppleUserLanguages = 1;
Country = US;
MultipleSessionEnabled = 1;
NSBoldSystemFont = ".LucidaGrandeUI-Bold";
NSButtonDelay = "0.4";
NSButtonPeriod = "0.075";
NSDocumentRevisionsDebugMode = YES;
NSDragAutoscrollAreaWidth = "5.0";
NSDragCancelLimit = "100000.0";
NSDraggingAutoscrollDelay = "0.4";
NSEnableAutoCollapseOutlineDuringDragsDefault = NO;
NSEnableAutoExpandOutlineDuringDragsDefault = YES;
NSFixedPitchFont = "Menlo-Regular";
NSFixedPitchFontSize = 11;
NSFont = Helvetica;
NSFontSize = 12;
NSInputServerLaunchTimeout = 60;
NSInterfaceStyle = macintosh;
NSLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
NSMargins = "72 72 90 90";
NSMenuFlashCount = 3;
NSMenuScrollingOffset = 3;
NSMenuScrollingSpeed = 5;
NSNavPanelFileLastListModeForOpenModeKey = 1;
NSNavPanelFileListModeForOpenMode2 = 1;
NSNavPanelSidebarKeyForOpen = (
);
NSNavPanelSidebarKeyForSave = (
);
NSNavRecentPlaces = (
"~/Documents",
"~/Documents/sample Project/learning_iOS",
"~/Desktop/firstPage",
"~/Desktop/SoftwareDepotIssue",
"~/Desktop"
);
NSPreferredSpellServerVendors = {
English = "NeXT-OpenStep";
};
NSPreferredWebServices = {
NSWebServicesProviderWebSearch = {
NSDefaultDisplayName = Google;
NSProviderIdentifier = "com.google.www";
};
};
NSQuotedKeystrokeBinding = "^q";
NSRequireAutoCollapseOutlineAfterDropsDefault = NO;
NSResetIncrementalSearchOnFailure = YES;
NSScrollAnimationEnabled = YES;
NSScrollerButtonAcceleration = 8;
NSScrollerButtonDelay = "0.5";
NSScrollerButtonPeriod = "0.05";
NSScrollerHasSeparateArrows = YES;
NSScrollerKnobCount = 2;
NSScrollerKnobDelay = "0.001";
NSSmartCMYKColorConversion = YES;
NSSystemFont = ".LucidaGrandeUI";
NSSystemFontSize = 13;
NSUIHeartBeatCycle = "0.03";
NSUseCocoaInputServers = YES;
NSUserDictionaryReplacementItems = (
);
NSWindowResizeTime = ".20";
NavPanelFileListModeForOpenMode = 1;
SGTRecentFileSearches = (
{
attributes = (
kMDItemDisplayName
);
enforceStrictMatch = 0;
exactMatch = 0;
name = istsu;
scope = 4;
type = "com.apple.finder";
values = (
istsu
);
}
);
WebKitAVFoundationEnabled = 1;
WebKitAccelerated2dCanvasEnabled = 0;
WebKitAcceleratedCompositingEnabled = 1;
WebKitAcceleratedDrawingEnabled = 0;
WebKitAllowAnimatedImageLoopingPreferenceKey = 1;
WebKitAllowAnimatedImagesPreferenceKey = 1;
WebKitAllowFileAccessFromFileURLs = 1;
WebKitAllowUniversalAccessFromFileURLs = 1;
WebKitApplicationCacheDefaultOriginQuota = 9223372036854775807;
WebKitApplicationCacheTotalQuota = 9223372036854775807;
WebKitApplicationChromeModeEnabledPreferenceKey = 0;
WebKitAsynchronousSpellCheckingEnabled = 0;
WebKitAuthorAndUserStylesEnabledPreferenceKey = 1;
WebKitBackForwardCacheExpirationIntervalKey = 1800;
WebKitBackspaceKeyNavigationEnabled = 1;
WebKitCSSCompositingEnabled = 1;
WebKitCSSCustomFilterEnabled = 1;
WebKitCSSGridLayoutEnabled = 0;
WebKitCSSRegionsEnabled = 1;
WebKitCacheModelPreferenceKey = 0;
WebKitCanvasUsesAcceleratedDrawing = 0;
WebKitCursiveFont = "Apple Chancery";
WebKitDNSPrefetchingEnabled = 0;
WebKitDOMPasteAllowedPreferenceKey = 0;
WebKitDatabasesEnabledPreferenceKey = 1;
WebKitDefaultFixedFontSize = 13;
WebKitDefaultFontSize = 16;
WebKitDefaultTextEncodingName = "ISO-8859-1";
WebKitDeveloperExtrasEnabledPreferenceKey = 0;
WebKitDiagnosticLoggingEnabled = 0;
WebKitDisplayImagesKey = 1;
WebKitEditableLinkBehavior = 0;
WebKitEnableInheritURIQueryComponent = 0;
WebKitExperimentalNotificationsEnabledPreferenceKey = 0;
WebKitFantasyFont = Papyrus;
WebKitFixedFont = Courier;
WebKitFrameFlatteningEnabled = 0;
WebKitFullScreenEnabled = 0;
WebKitHiddenPageCSSAnimationSuspensionEnabled = 0;
WebKitHiddenPageDOMTimerThrottlingEnabled = 0;
WebKitHyperlinkAuditingEnabled = 1;
WebKitJavaEnabled = 1;
WebKitJavaScriptCanAccessClipboard = 0;
WebKitJavaScriptCanOpenWindowsAutomatically = 1;
WebKitJavaScriptEnabled = 1;
WebKitJavaScriptExperimentsEnabledPreferenceKey = 0;
WebKitKerningAndLigaturesEnabledByDefault = 1;
WebKitLoadSiteIconsKey = 0;
WebKitLocalFileContentSniffingEnabledPreferenceKey = 0;
WebKitLocalStorageEnabledPreferenceKey = 1;
WebKitLowPowerVideoAudioBufferSizeEnabled = 0;
WebKitMediaPlaybackAllowsInline = 1;
WebKitMediaPlaybackRequiresUserGesture = 0;
WebKitMinimumFontSize = 0;
WebKitMinimumLogicalFontSize = 9;
WebKitNotificationsEnabled = 1;
WebKitOfflineWebApplicationCacheEnabled = 0;
WebKitPDFDisplayMode = 1;
WebKitPDFScaleFactor = 0;
WebKitPageCacheSupportsPluginsPreferenceKey = 1;
WebKitPictographFont = "Apple Color Emoji";
WebKitPlugInSnapshottingEnabled = 0;
WebKitPluginsEnabled = 1;
WebKitPrivateBrowsingEnabled = 0;
WebKitQTKitEnabled = 1;
WebKitRegionBasedColumnsEnabled = 0;
WebKitRequestAnimationFrameEnabled = 1;
WebKitRespectStandardStyleKeyEquivalents = 0;
WebKitSansSerifFont = Helvetica;
WebKitScreenFontSubstitutionEnabled = 0;
WebKitSerifFont = Times;
WebKitShouldDisplayCaptions = 0;
WebKitShouldDisplaySubtitles = 0;
WebKitShouldDisplayTextDescriptions = 0;
WebKitShouldPrintBackgroundsPreferenceKey = 0;
WebKitShouldRespectImageOrientation = 0;
WebKitShowDebugBorders = 0;
WebKitShowRepaintCounter = 0;
WebKitShowsToolTipOverTruncatedText = 0;
WebKitShowsURLsInToolTips = 0;
WebKitShrinksStandaloneImagesToFit = 0;
WebKitSpatialNavigationEnabled = 0;
WebKitStandardFont = Times;
WebKitStorageBlockingPolicy = 0;
WebKitSuppressesIncrementalRendering = 0;
WebKitTabToLinksPreferenceKey = 0;
WebKitTextAreasAreResizable = 0;
WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey = 1;
WebKitUseLegacyTextAlignPositionedElementBehavior = 0;
WebKitUsePreHTML5ParserQuirks = 0;
WebKitUseSiteSpecificSpoofing = 0;
WebKitUserStyleSheetEnabledPreferenceKey = 0;
WebKitUserStyleSheetLocationPreferenceKey = "";
WebKitUsesEncodingDetector = 0;
WebKitUsesPageCachePreferenceKey = 1;
WebKitWantsBalancedSetDefersLoadingBehavior = 0;
WebKitWebArchiveDebugModeEnabledPreferenceKey = 0;
WebKitWebAudioEnabled = 0;
WebKitWebGLEnabled = 0;
WebKitWebSecurityEnabled = 1;
WebKitXSSAuditorEnabled = 1;
WebKitZoomsTextOnly = 1;
"com.apple.AppleModemSettingTool.LastCountryCode" = US;
"com.apple.ColorSync.Devices" = {
"Device.cmra.00000000-0000-0000-0000-000000533630" = {
DeviceDescriptions = {
"en_US" = "NO NAME";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.30303441-3030-3930-4637-393830304637" = {
DeviceDescriptions = {
"en_US" = "Lumia 520";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.37616133-3566-6339-6362-303662336639" = {
DeviceDescriptions = {
"en_US" = iPhone;
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
};
"com.apple.TimeZonePref.Last_Selected_City" = (
"37.36883",
"-122.0363",
0,
"America/Los_Angeles",
US,
Sunnyvale,
"U.S.A.",
Sunnyvale,
"U.S.A.",
"DEPRECATED IN 10.6"
);
"com.apple.preferences.timezone.selected_city" = {
CountryCode = US;
GeonameID = 5400075;
Latitude = "37.36883";
LocalizedNames = {
ar = "\U0633\U0627\U0646\U064a\U0641\U064a\U0644";
ca = Sunnyvale;
cs = Sunnyvale;
da = Sunnyvale;
de = Sunnyvale;
el = Sunnyvale;
en = Sunnyvale;
es = Sunnyvale;
fi = Sunnyvale;
fr = Sunnyvale;
he = "\U05e1\U05d0\U05e0\U05d9\U05d5\U05d5\U05dc";
hr = Sunnyvale;
hu = Sunnyvale;
id = Sunnyvale;
it = Sunnyvale;
ja = "\U30b5\U30cb\U30fc\U30d9\U30fc\U30eb";
ko = "\Uc11c\Ub2c8\Ubca0\Uc77c";
ms = Sunnyvale;
nb = Sunnyvale;
nl = Sunnyvale;
pl = Sunnyvale;
pt = Sunnyvale;
"pt-PT" = Sunnyvale;
ro = Sunnyvale;
ru = "\U0421\U0430\U043d\U043d\U0438\U0432\U0435\U0439\U043b";
sk = Sunnyvale;
sv = Sunnyvale;
th = Sunnyvale;
tr = Sunnyvale;
uk = "\U0421\U0430\U043d\U043d\U0456\U0432\U0435\U0439\U043b";
vi = Sunnyvale;
"zh-Hans" = "\U6851\U5c3c\U7ef4\U5c14";
"zh-Hant" = "\U6851\U5c3c\U7dad\U723e";
};
Longitude = "-122.0363";
Name = Sunnyvale;
Population = 140081;
RegionalCode = CA;
TimeZoneName = "America/Los_Angeles";
Version = 1;
};
"com.apple.springing.delay" = "0.5";
"com.apple.springing.enabled" = 1;
"com.apple.trackpad.enableSecondaryClick" = 1;
"com.apple.trackpad.fiveFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.fourFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerVertSwipeGesture" = 2;
"com.apple.trackpad.momentumScroll" = 1;
"com.apple.trackpad.pinchGesture" = 1;
"com.apple.trackpad.rotateGesture" = 1;
"com.apple.trackpad.scrollBehavior" = 2;
"com.apple.trackpad.threeFingerDragGesture" = 0;
"com.apple.trackpad.threeFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.threeFingerTapGesture" = 2;
"com.apple.trackpad.threeFingerVertSwipeGesture" = 2;
"com.apple.trackpad.twoFingerDoubleTapGesture" = 1;
"com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture" = 3;
"com.apple.trackpad.version" = 5;
"com.apple.updatesettings_did_disable_ftp" = 1;
test1 = test1;
test2 = test2;

Related

Vulkan resolve attachment is flipped

I use pResolveAttachment to implement MSAA with Vulkan on Android, but the result is flipped.
VkSubpassDescription subpassDesc;
subpassDesc.flags = 0;
subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpassDesc.inputAttachmentCount = 0;
subpassDesc.pInputAttachments = nullptr;
subpassDesc.colorAttachmentCount = colorAttachmentCount;
subpassDesc.pColorAttachments = attachmentRefs.data();
subpassDesc.pResolveAttachments = resolveAttachmentCount > 0 ? resolveReferences.data() : nullptr;
subpassDesc.pDepthStencilAttachment = depthStencilAttachment;
subpassDesc.preserveAttachmentCount = 0;
subpassDesc.pPreserveAttachments = nullptr;
// TIPS
resolveReferences[resolveAttachmentCount].attachment = attachmentCount;
resolveReferences[resolveAttachmentCount].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
resolveAttachmentCount++;
....
subpassDesc.pResolveAttachments = resolveAttachmentCount > 0 ? resolveReferences.data() : nullptr;

Replacement for deprecated NXOpenEventStatus?

I need to get the tracking speed of the mouse on OSX 10.13. I found this code on the internet but NXOpenEventStatus is deprecated (as is IOHIDGetAccelerationWithKey), is there an alternative way?
#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/event_status_driver.h>
int main()
{
kern_return_t kr;
double trackpadAcceleration, mouseAcceleration;
NXEventHandle h = 0;
h = NXOpenEventStatus();
if (h == nil)
return -1;
kr = IOHIDGetAccelerationWithKey( h, CFSTR(kIOHIDMouseAccelerationType), &mouseAcceleration);
return 0;
}
Since NXOpenEventStatus and IOHIDGetAccelerationWithKey are both part of the open-source IOKit distribution, you can look at how they're implemented. It turns out we can do what those functions do, using only non-deprecated functions.
To boil it down to the bare minimum, you can get a dictionary of the HID system's properties like this:
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IOHIDSystem");
CFDictionaryRef parameters = IORegistryEntryCreateCFProperty(service, CFSTR(kIOHIDParametersKey), kCFAllocatorDefault, kNilOptions);
NSLog(#"%#", parameters);
IOObjectRelease(service);
}
return 0;
}
Output (for me on macOS 10.13.4):
2018-04-05 17:06:55.560590-0500 accel[11924:131983] {
ActuateDetents = 1;
Clicking = 0;
DragLock = 0;
Dragging = 0;
EjectDelay = 0;
FirstClickThreshold = 1;
ForceSuppressed = 0;
HIDClickSpace = (
5,
5
);
HIDClickTime = 500000000;
HIDDefaultParameters = 1;
HIDF12EjectDelay = 250;
HIDFKeyMode = 1;
HIDInitialKeyRepeat = 250000000;
HIDKeyRepeat = 33333333;
HIDKeyboardModifierMappingPairs = (
);
HIDMouseAcceleration = 98304;
HIDMouseKeysOptionToggles = 0;
HIDPointerAcceleration = 45056;
HIDPointerButtonMode = 2;
HIDScrollAcceleration = 20480;
HIDScrollZoomModifierMask = 262144;
HIDSlowKeysDelay = 0;
HIDStickyKeysDisabled = 0;
HIDStickyKeysOn = 0;
HIDStickyKeysShiftToggles = 0;
HIDTrackpadAcceleration = 57344;
HIDWaitCursorFrameInterval = 16666667;
JitterNoClick = 1;
JitterNoMove = 1;
MouseButtonDivision = 55;
MouseButtonMode = TwoButton;
MouseHorizontalScroll = 1;
MouseMomentumScroll = 1;
MouseOneFingerDoubleTapGesture = 0;
MouseTwoFingerDoubleTapGesture = 0;
MouseTwoFingerHorizSwipeGesture = 0;
MouseVerticalScroll = 1;
"OutsidezoneNoAction When Typing" = 1;
"PalmNoAction Permanent" = 1;
"PalmNoAction When Typing" = 1;
SecondClickThreshold = 1;
"Trackpad Jitter Milliseconds" = 192;
TrackpadCornerSecondaryClick = 0;
TrackpadFiveFingerPinchGesture = 0;
TrackpadFourFingerHorizSwipeGesture = 2;
TrackpadFourFingerPinchGesture = 0;
TrackpadFourFingerVertSwipeGesture = 0;
TrackpadHandResting = 1;
TrackpadHorizScroll = 1;
TrackpadMomentumScroll = 1;
TrackpadPinch = 1;
TrackpadRightClick = 1;
TrackpadRotate = 1;
TrackpadScroll = 1;
TrackpadThreeFingerDrag = 0;
TrackpadThreeFingerHorizSwipeGesture = 2;
TrackpadThreeFingerTapGesture = 0;
TrackpadThreeFingerVertSwipeGesture = 0;
TrackpadThreeFingersRightClick = 0;
TrackpadTwoFingerDoubleTapGesture = 1;
TrackpadTwoFingerFromRightEdgeSwipeGesture = 0;
TwofingerNoAction = 1;
USBMouseStopsTrackpad = 0;
"Use Panther Settings for W" = 0;
UserPreferences = 1;
version = 1;
}
Program ended with exit code: 0
The kIOHIDMouseAccelerationType constant has value HIDMouseAcceleration. I also see HIDPointerAcceleration and HIDTrackpadAcceleration in there. There are kIOHID... constants for those too.
Note also that IOHIDGetAccelerationWithKey divides the registry value by 65536 before returning it. IOHIDSetAccelerationWithKey performs the opposite transformation.

Calculate the price based on height and width

I need to make a module that allow the user to enter width and height , and then it should calculate the price based on the height and width .
thanks in advance
let's say that you want to do it on the product ID N° 1 from the product page :
first add two inputs fields in your product.tpl ( or in your module.tpl called in product.tpl)
<input name="height"><br>
<input name="width">
now you need to get it in your module.php to change the price dynamicly :
$id_product = 1;
$newPrice = 0;
$height = Tools::getValue('height');
$width = Tools::getValue('width');
//Price rules (change with your rules)
if($height > 10 && $width > 10) $newPrice = 10;
$specific_price = new SpecificPrice();
$specific_price->price = $newPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
and if you want add it to cart
$cart->id_lang = (int)($this->context->cookie->id_lang);
$cart->id_currency = (int)($this->context->cookie->id_currency);
$cart->updateQty($qte, $id_product);
and after order is done you put the normal price, so override the orderConfirmation controller in override/controllers/front/OrderConfirmationController.php:
class OrderConfirmationController extends OrderConfirmationControllerCore
{
public $ssl = true;
public $php_self = 'order-confirmation';
public $id_cart;
public $id_module;
public $id_order;
public $reference;
public $secure_key;
public function getPriceBack($id_product){
$normalPrice = Product::getPriceStatic($id_product);
$specific_price = new SpecificPrice();
$specific_price->price = $normalPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
}
public function init()
{
parent::init();
$this->id_cart = (int)(Tools::getValue('id_cart', 0));
$is_guest = false;
/* get normal price back */
$id_product = 1;
self::getPriceBack($id_product);
/* check if the cart has been made by a Guest customer, for redirect link */
if (Cart::isGuestCartByCartId($this->id_cart)) {
$is_guest = true;
$redirectLink = 'index.php?controller=guest-tracking';
} else {
$redirectLink = 'index.php?controller=history';
}
$this->id_module = (int)(Tools::getValue('id_module', 0));
$this->id_order = Order::getOrderByCartId((int)($this->id_cart));
$this->secure_key = Tools::getValue('key', false);
$order = new Order((int)($this->id_order));
if ($is_guest) {
$customer = new Customer((int)$order->id_customer);
$redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
}
if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
}
$this->reference = $order->reference;
if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
Tools::redirect($redirectLink);
}
$module = Module::getInstanceById((int)($this->id_module));
if ($order->module != $module->name) {
Tools::redirect($redirectLink);
}
}
}
after the order is done you have to empty the cart with id_product and delete rule in dbb :
$this->context->cart->deleteProduct(1);
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'specific_price WHERE id_customer='.(int)$this->context->customer->id);
it s just an example and can not use without variables tests and maybe put constante for your product id concerned, hope it helps

using X264 and librtmp to send live camera frame, but the flash can't show

I am using X264 and librtmp to send my live camera frame, all the things seems right. but my web test flash can't show the correct video. Sometimes it seems correct, but when I re-click play button, it doesn't show any picture on the flash.
Here is my X264 config code
x264_param_default_preset(&x264param, "ultrafast", "zerolatency");
x264param.i_threads = 2;
x264param.i_width = width;
x264param.i_height = height;
x264param.i_log_level = X264_LOG_DEBUG;
x264param.i_fps_num = x264param.i_timebase_num= fps;
x264param.i_fps_den = x264param.i_timebase_den=1;
x264param.i_frame_total = 0;
x264param.i_frame_reference =1;
//x264param.i_frame_reference = 2;
x264param.i_keyint_min = 25;
x264param.i_keyint_max = fps*3;
x264param.i_scenecut_threshold = 40;
x264param.b_deblocking_filter = 1;
x264param.b_cabac = 0;
x264param.analyse.i_trellis = 0;
x264param.analyse.b_chroma_me = 1;
x264param.vui.i_sar_width = 0;
x264param.vui.i_sar_height = 0;
x264param.i_bframe_bias = 0;
x264param.b_interlaced= 0;
x264param.analyse.i_subpel_refine = 6; /* 0..5 -> 1..6 */
x264param.analyse.i_me_method = X264_ME_DIA;//X264_ME_HEX?X264_ME_DIA
x264param.analyse.i_me_range = 16;
x264param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_AUTO;
x264param.i_deblocking_filter_alphac0 = 0;
x264param.i_deblocking_filter_beta = 0;
//x264param.analyse.intra = X264_ANALYSE_I4x4;
x264param.analyse.intra = X264_ANALYSE_I4x4;// | X264_ANALYSE_PSUB16x16 | X264_ANALYSE_BSUB16x16;
x264param.analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16 | X264_ANALYSE_BSUB16x16;
//edit 2014-7-28
x264param.analyse.b_transform_8x8 = 1;
//x264param.analyse.b_transform_8x8 = 0;
x264param.analyse.b_fast_pskip = 1;
x264param.i_bframe = 0;
//x264param.b_intra_refresh
x264param.analyse.b_weighted_bipred = 0;
//// Intra refres:
x264param.i_keyint_max = 250;
x264param.b_intra_refresh = 0;
////Rate control:
//x264param.rc.i_rc_method = X264_RC_CRF;
//Rate Control
x264param.rc.f_ip_factor = 1.4f;
x264param.rc.f_pb_factor = 1.3f;
x264param.rc.f_qcompress = 1.0;
x264param.rc.i_qp_min = 20;//20;
x264param.rc.i_qp_max = 32;
x264param.rc.i_qp_step = 1;
switch (0)
{
case 0: /* 1 PASS ABR */
x264param.rc.i_rc_method = X264_RC_ABR;
x264param.rc.i_bitrate = 300; // max = 5000
x264param.rc.b_mb_tree = 0;
break;
case 1: /* 1 PASS CQ */
x264param.rc.i_rc_method = X264_RC_CQP;
x264param.rc.i_qp_constant = 26;//10 - 51
break;
}
//For streaming:
x264param.b_repeat_headers = 1;
x264param.b_annexb = 1;
x264_param_apply_profile(&x264param, "baseline");
encoder = x264_encoder_open(&x264param);
x264_picture_init( &pic_in );
x264_picture_alloc(&pic_in, X264_CSP_I420, width, height);
pic_in.img.i_csp = X264_CSP_I420|X264_CSP_VFLIP;
pic_in.img.i_plane = 3;
pic_in.i_type = X264_TYPE_AUTO;
Sending To RTMP:
sws_scale(convertCtx,&a,&scribe,0,height, pic_in.img.plane, pic_in.img.i_stride);
int i_nal;
int i_frame_size = x264_encoder_encode( encoder, &nal, &i_nal, &pic_in, &pic_out );
if(i_frame_size <= 0){
printf("\t!!!FAILED encode frame \n");
}else{
for (int i = 0,last=0; i < i_nal;i++)
{
fwrite(nal[i].p_payload, 1, i_frame_size-last, fpw1);
if (nal[i].i_type == NAL_SPS) {
sps_len = nal[i].i_payload-4;
sps = new unsigned char[sps_len];
memcpy(sps,nal[i].p_payload+4,sps_len);
} else if (nal[i].i_type == NAL_PPS) {
pps_len = nal[i].i_payload-4;
pps = new unsigned char[sps_len];
memcpy(pps,nal[i].p_payload+4,pps_len);
send_video_sps_pps();
free(sps);
free(pps);
} else {
send_rtmp_video(nal[i].p_payload,i_frame_size-last);
break;
}
last += nal[i].i_payload;
}
}
Send PPS and SPS
void send_video_sps_pps(){
if(rtmp!= NULL){
RTMPPacket * packet;
unsigned char * body;
int i;
packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+1024);
memset(packet,0,RTMP_HEAD_SIZE);
packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
body = (unsigned char *)packet->m_body;
i = 0;
body[i++] = 0x17;
body[i++] = 0x00;
body[i++] = 0x00;
body[i++] = 0x00;
body[i++] = 0x00;
/*AVCDecoderConfigurationRecord*/
body[i++] = 0x01;
body[i++] = sps[1];
body[i++] = sps[2];
body[i++] = sps[3];
body[i++] = 0xff;
/*sps*/
body[i++] = 0xe1;
body[i++] = (sps_len >> 8) & 0xff;
body[i++] = sps_len & 0xff;
memcpy(&body[i],sps,sps_len);
i += sps_len;
/*pps*/
body[i++] = 0x01;
body[i++] = (pps_len >> 8) & 0xff;
body[i++] = (pps_len) & 0xff;
memcpy(&body[i],pps,pps_len);
i += pps_len;
packet->m_packetType = RTMP_PACKET_TYPE_VIDEO;
packet->m_nBodySize = i;
packet->m_nChannel = 0x04;
packet->m_nTimeStamp = 0;
packet->m_hasAbsTimestamp = 0;
packet->m_headerType = RTMP_PACKET_SIZE_MEDIUM;
packet->m_nInfoField2 = rtmp->m_stream_id;
RTMP_SendPacket(rtmp,packet,TRUE);
free(packet);
rtmp_start_time = GetTickCount();
}else{
std::cout<<"RTMP is not ready"<<std::endl;
}
}
Send video Frame
void send_rtmp_video(unsigned char * buf,int len){
RTMPPacket * packet;
long timeoffset = GetTickCount() - rtmp_start_time;
int type = buf[0]&0x1f;
packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+len+9);
memset(packet,0,RTMP_HEAD_SIZE);
packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
packet->m_nBodySize = len + 9;
/*send video packet*/
unsigned char *body = (unsigned char *)packet->m_body;
memset(body,0,len+9);
/*key frame*/
body[0] = 0x27;
if (type == NAL_SLICE_IDR) {
body[0] = 0x17;
}
body[1] = 0x01; /*nal unit*/
body[2] = 0x00;
body[3] = 0x00;
body[4] = 0x00;
body[5] = (len >> 24) & 0xff;
body[6] = (len >> 16) & 0xff;
body[7] = (len >> 8) & 0xff;
body[8] = (len ) & 0xff;
/*copy data*/
memcpy(&body[9],buf,len);
packet->m_hasAbsTimestamp = 0;
packet->m_packetType = RTMP_PACKET_TYPE_VIDEO;
if(rtmp != NULL){
packet->m_nInfoField2 = rtmp->m_stream_id;
}
packet->m_nChannel = 0x04;
packet->m_headerType = RTMP_PACKET_SIZE_LARGE;
packet->m_nTimeStamp = timeoffset;
if(rtmp != NULL){
RTMP_SendPacket(rtmp,packet,TRUE);
}
free(packet);
}
Try changing:
pps = new unsigned char[sps_len];
to:
pps = new unsigned char[pps_len];

Zedgraph creating too small image

The output of my graph is really small, I can't really see the values at the x and y axis. Is there a way to change this, so the graph is bigger?
My code to output the graph is:
ZedGraphControl zc = new ZedGraphControl();
GraphPane pane = zc.GraphPane;
PointPairList list1 = new PointPairList();
LineItem curve1;
pane.Title.Text = title;
pane.XAxis.Title.Text = xAxisTitle;
pane.XAxis.Scale.Min = 0;
pane.XAxis.Scale.Max = 11;
pane.YAxis.Scale.Min = 1;
pane.YAxis.Scale.Max = 12;
pane.YAxis.Title.Text = yAXisTitle;
Int32 totalCount = ds.Tables[objectName].Rows.Count;
double[] xVals = new double[totalCount], yVals = new double[totalCount];
for (int i = 0; i < totalCount; i++)
{
xVals[i] = Convert.ToDouble(ds.Tables[objectName].Rows[i]["ntotal"]);
yVals[i] = Convert.ToDouble(ds.Tables[objectName].Rows[i]["isomonth"]);
}
list1.Add(xVals, yVals);
curve1 = pane.AddCurve("Temp curve", list1, Color.Green, SymbolType.Circle);
for (int i = 0; i < totalCount; i++)
{
TextObj t = new TextObj("Teest", curve1.Points[i].Y, curve1.Points[i].X);
t.FontSpec.Border.IsVisible = false;
pane.GraphObjList.Add(t);
}
curve1.Line.Width = 1.0F;
pane.GetImage().Save(outPutDestination, ImageFormat.Png);
pane.AxisChange();
GetImage() function gets the current size of the pane, so we just have to increase the size of the entire pane(i.e: dock & maximize the window & then use the method to get the image).
DockStyle currentStyle = zedGraphControl1.Dock;
var currentWindowState = this.WindowState;
zedGraphControl1.Dock = DockStyle.Fill;
this.WindowState = FormWindowState.Maximized;
zedGraphControl1.GetImage ().Save ( #"c:\Image_1.png" );
this.WindowState = currentWindowState;
zedGraphControl1.Dock = currentStyle;