mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[CmdPal][AOT] Using ExprTk to make the Cal extension AOT-compatible (#39972)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR replaces the original Mages-based expression evaluation engine with a WinRT-wrapped version of Exprtk in the CmdPalCalculator module. ### Key Changes **Expression Engine:** - All expression parsing and evaluation now use Exprtk (via a WinRT wrapper) instead of Mages. **Base Conversion Handling:** - Since Exprtk does not support non-decimal (binary, octal, hexadecimal) input natively, added logic to convert all such inputs to decimal before evaluation. **Code Structure:** - The overall logic and API surface remain unchanged except for the engine and base conversion handling. - All previous Mages references and dependencies have been removed. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] **Closes:** #xxx - [ ] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
This commit is contained in:
3
.github/actions/spell-check/expect.txt
vendored
3
.github/actions/spell-check/expect.txt
vendored
@@ -69,6 +69,7 @@ appwiz
|
|||||||
APSTUDIO
|
APSTUDIO
|
||||||
AQS
|
AQS
|
||||||
ARandom
|
ARandom
|
||||||
|
Arash
|
||||||
ARCHITEW
|
ARCHITEW
|
||||||
ARemapped
|
ARemapped
|
||||||
ARPINSTALLLOCATION
|
ARPINSTALLLOCATION
|
||||||
@@ -469,6 +470,7 @@ EXPCMDFLAGS
|
|||||||
EXPCMDSTATE
|
EXPCMDSTATE
|
||||||
explr
|
explr
|
||||||
exppowertoys
|
exppowertoys
|
||||||
|
exprtk
|
||||||
exptas
|
exptas
|
||||||
exsb
|
exsb
|
||||||
exstyle
|
exstyle
|
||||||
@@ -1150,6 +1152,7 @@ PARTIALCONFIRMATIONDIALOGTITLE
|
|||||||
PATCOPY
|
PATCOPY
|
||||||
PATHMUSTEXIST
|
PATHMUSTEXIST
|
||||||
PATINVERT
|
PATINVERT
|
||||||
|
partow
|
||||||
PATPAINT
|
PATPAINT
|
||||||
pbc
|
pbc
|
||||||
pbi
|
pbi
|
||||||
|
|||||||
@@ -3,226 +3,227 @@
|
|||||||
"UseMinimatch": false,
|
"UseMinimatch": false,
|
||||||
"SignBatches": [
|
"SignBatches": [
|
||||||
{
|
{
|
||||||
"MatchedPath": [
|
"MatchedPath": [
|
||||||
"*.resources.dll",
|
"*.resources.dll",
|
||||||
|
|
||||||
"WinUI3Apps\\Assets\\Settings\\Scripts\\*.ps1",
|
|
||||||
|
|
||||||
"PowerToys.ActionRunner.exe",
|
"WinUI3Apps\\Assets\\Settings\\Scripts\\*.ps1",
|
||||||
"PowerToys.Update.exe",
|
|
||||||
"PowerToys.BackgroundActivatorDLL.dll",
|
|
||||||
"Notifications.dll",
|
|
||||||
"os-detection.dll",
|
|
||||||
"PowerToys.exe",
|
|
||||||
"PowerToys.FilePreviewCommon.dll",
|
|
||||||
"PowerToys.Interop.dll",
|
|
||||||
"Tools\\PowerToys.BugReportTool.exe",
|
|
||||||
"StylesReportTool\\PowerToys.StylesReportTool.exe",
|
|
||||||
"Telemetry.dll",
|
|
||||||
"PowerToys.ManagedTelemetry.dll",
|
|
||||||
"PowerToys.ManagedCommon.dll",
|
|
||||||
"PowerToys.Common.UI.dll",
|
|
||||||
"PowerToys.Settings.UI.Lib.dll",
|
|
||||||
"PowerToys.GPOWrapper.dll",
|
|
||||||
"PowerToys.GPOWrapperProjection.dll",
|
|
||||||
"PowerToys.AllExperiments.dll",
|
|
||||||
|
|
||||||
"PowerToys.AlwaysOnTop.exe",
|
"PowerToys.ActionRunner.exe",
|
||||||
"PowerToys.AlwaysOnTopModuleInterface.dll",
|
"PowerToys.Update.exe",
|
||||||
|
"PowerToys.BackgroundActivatorDLL.dll",
|
||||||
|
"Notifications.dll",
|
||||||
|
"os-detection.dll",
|
||||||
|
"PowerToys.exe",
|
||||||
|
"PowerToys.FilePreviewCommon.dll",
|
||||||
|
"PowerToys.Interop.dll",
|
||||||
|
"Tools\\PowerToys.BugReportTool.exe",
|
||||||
|
"StylesReportTool\\PowerToys.StylesReportTool.exe",
|
||||||
|
"Telemetry.dll",
|
||||||
|
"CalculatorEngineCommon.dll",
|
||||||
|
"PowerToys.ManagedTelemetry.dll",
|
||||||
|
"PowerToys.ManagedCommon.dll",
|
||||||
|
"PowerToys.Common.UI.dll",
|
||||||
|
"PowerToys.Settings.UI.Lib.dll",
|
||||||
|
"PowerToys.GPOWrapper.dll",
|
||||||
|
"PowerToys.GPOWrapperProjection.dll",
|
||||||
|
"PowerToys.AllExperiments.dll",
|
||||||
|
|
||||||
"PowerToys.CmdNotFoundModuleInterface.dll",
|
"PowerToys.AlwaysOnTop.exe",
|
||||||
"PowerToys.CmdNotFound.dll",
|
"PowerToys.AlwaysOnTopModuleInterface.dll",
|
||||||
|
|
||||||
"PowerToys.ColorPicker.dll",
|
"PowerToys.CmdNotFoundModuleInterface.dll",
|
||||||
"PowerToys.ColorPickerUI.dll",
|
"PowerToys.CmdNotFound.dll",
|
||||||
"PowerToys.ColorPickerUI.exe",
|
|
||||||
|
|
||||||
"PowerToys.CropAndLockModuleInterface.dll",
|
"PowerToys.ColorPicker.dll",
|
||||||
"PowerToys.CropAndLock.exe",
|
"PowerToys.ColorPickerUI.dll",
|
||||||
|
"PowerToys.ColorPickerUI.exe",
|
||||||
|
|
||||||
"PowerToys.PowerOCRModuleInterface.dll",
|
"PowerToys.CropAndLockModuleInterface.dll",
|
||||||
"PowerToys.PowerOCR.dll",
|
"PowerToys.CropAndLock.exe",
|
||||||
"PowerToys.PowerOCR.exe",
|
|
||||||
|
|
||||||
"PowerToys.AdvancedPasteModuleInterface.dll",
|
"PowerToys.PowerOCRModuleInterface.dll",
|
||||||
"WinUI3Apps\\PowerToys.AdvancedPaste.exe",
|
"PowerToys.PowerOCR.dll",
|
||||||
"WinUI3Apps\\PowerToys.AdvancedPaste.dll",
|
"PowerToys.PowerOCR.exe",
|
||||||
|
|
||||||
"PowerToys.AwakeModuleInterface.dll",
|
"PowerToys.AdvancedPasteModuleInterface.dll",
|
||||||
"PowerToys.Awake.exe",
|
"WinUI3Apps\\PowerToys.AdvancedPaste.exe",
|
||||||
"PowerToys.Awake.dll",
|
"WinUI3Apps\\PowerToys.AdvancedPaste.dll",
|
||||||
|
|
||||||
"fancyzones.dll",
|
"PowerToys.AwakeModuleInterface.dll",
|
||||||
"PowerToys.FancyZonesEditor.exe",
|
"PowerToys.Awake.exe",
|
||||||
"PowerToys.FancyZonesEditor.dll",
|
"PowerToys.Awake.dll",
|
||||||
"PowerToys.FancyZonesEditorCommon.dll",
|
|
||||||
"PowerToys.FancyZonesModuleInterface.dll",
|
|
||||||
"PowerToys.FancyZones.exe",
|
|
||||||
|
|
||||||
"PowerToys.GcodePreviewHandler.dll",
|
"fancyzones.dll",
|
||||||
"PowerToys.GcodePreviewHandler.exe",
|
"PowerToys.FancyZonesEditor.exe",
|
||||||
"PowerToys.GcodePreviewHandlerCpp.dll",
|
"PowerToys.FancyZonesEditor.dll",
|
||||||
"PowerToys.GcodeThumbnailProvider.dll",
|
"PowerToys.FancyZonesEditorCommon.dll",
|
||||||
"PowerToys.GcodeThumbnailProvider.exe",
|
"PowerToys.FancyZonesModuleInterface.dll",
|
||||||
"PowerToys.GcodeThumbnailProviderCpp.dll",
|
"PowerToys.FancyZones.exe",
|
||||||
"PowerToys.ManagedTelemetry.dll",
|
|
||||||
"PowerToys.MarkdownPreviewHandler.dll",
|
|
||||||
"PowerToys.MarkdownPreviewHandler.exe",
|
|
||||||
"PowerToys.MarkdownPreviewHandlerCpp.dll",
|
|
||||||
"PowerToys.MonacoPreviewHandler.dll",
|
|
||||||
"PowerToys.MonacoPreviewHandler.exe",
|
|
||||||
"PowerToys.MonacoPreviewHandlerCpp.dll",
|
|
||||||
"PowerToys.PdfPreviewHandler.dll",
|
|
||||||
"PowerToys.PdfPreviewHandler.exe",
|
|
||||||
"PowerToys.PdfPreviewHandlerCpp.dll",
|
|
||||||
"PowerToys.PdfThumbnailProvider.dll",
|
|
||||||
"PowerToys.PdfThumbnailProvider.exe",
|
|
||||||
"PowerToys.PdfThumbnailProviderCpp.dll",
|
|
||||||
"PowerToys.powerpreview.dll",
|
|
||||||
"PowerToys.PreviewHandlerCommon.dll",
|
|
||||||
"PowerToys.QoiPreviewHandler.dll",
|
|
||||||
"PowerToys.QoiPreviewHandler.exe",
|
|
||||||
"PowerToys.QoiPreviewHandlerCpp.dll",
|
|
||||||
"PowerToys.QoiThumbnailProvider.dll",
|
|
||||||
"PowerToys.QoiThumbnailProvider.exe",
|
|
||||||
"PowerToys.QoiThumbnailProviderCpp.dll",
|
|
||||||
"PowerToys.StlThumbnailProvider.dll",
|
|
||||||
"PowerToys.StlThumbnailProvider.exe",
|
|
||||||
"PowerToys.StlThumbnailProviderCpp.dll",
|
|
||||||
"PowerToys.SvgPreviewHandler.dll",
|
|
||||||
"PowerToys.SvgPreviewHandler.exe",
|
|
||||||
"PowerToys.SvgPreviewHandlerCpp.dll",
|
|
||||||
"PowerToys.SvgThumbnailProvider.dll",
|
|
||||||
"PowerToys.SvgThumbnailProvider.exe",
|
|
||||||
"PowerToys.SvgThumbnailProviderCpp.dll",
|
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.HostsModuleInterface.dll",
|
"PowerToys.GcodePreviewHandler.dll",
|
||||||
"WinUI3Apps\\PowerToys.HostsUILib.dll",
|
"PowerToys.GcodePreviewHandler.exe",
|
||||||
"WinUI3Apps\\PowerToys.Hosts.dll",
|
"PowerToys.GcodePreviewHandlerCpp.dll",
|
||||||
"WinUI3Apps\\PowerToys.Hosts.exe",
|
"PowerToys.GcodeThumbnailProvider.dll",
|
||||||
|
"PowerToys.GcodeThumbnailProvider.exe",
|
||||||
|
"PowerToys.GcodeThumbnailProviderCpp.dll",
|
||||||
|
"PowerToys.ManagedTelemetry.dll",
|
||||||
|
"PowerToys.MarkdownPreviewHandler.dll",
|
||||||
|
"PowerToys.MarkdownPreviewHandler.exe",
|
||||||
|
"PowerToys.MarkdownPreviewHandlerCpp.dll",
|
||||||
|
"PowerToys.MonacoPreviewHandler.dll",
|
||||||
|
"PowerToys.MonacoPreviewHandler.exe",
|
||||||
|
"PowerToys.MonacoPreviewHandlerCpp.dll",
|
||||||
|
"PowerToys.PdfPreviewHandler.dll",
|
||||||
|
"PowerToys.PdfPreviewHandler.exe",
|
||||||
|
"PowerToys.PdfPreviewHandlerCpp.dll",
|
||||||
|
"PowerToys.PdfThumbnailProvider.dll",
|
||||||
|
"PowerToys.PdfThumbnailProvider.exe",
|
||||||
|
"PowerToys.PdfThumbnailProviderCpp.dll",
|
||||||
|
"PowerToys.powerpreview.dll",
|
||||||
|
"PowerToys.PreviewHandlerCommon.dll",
|
||||||
|
"PowerToys.QoiPreviewHandler.dll",
|
||||||
|
"PowerToys.QoiPreviewHandler.exe",
|
||||||
|
"PowerToys.QoiPreviewHandlerCpp.dll",
|
||||||
|
"PowerToys.QoiThumbnailProvider.dll",
|
||||||
|
"PowerToys.QoiThumbnailProvider.exe",
|
||||||
|
"PowerToys.QoiThumbnailProviderCpp.dll",
|
||||||
|
"PowerToys.StlThumbnailProvider.dll",
|
||||||
|
"PowerToys.StlThumbnailProvider.exe",
|
||||||
|
"PowerToys.StlThumbnailProviderCpp.dll",
|
||||||
|
"PowerToys.SvgPreviewHandler.dll",
|
||||||
|
"PowerToys.SvgPreviewHandler.exe",
|
||||||
|
"PowerToys.SvgPreviewHandlerCpp.dll",
|
||||||
|
"PowerToys.SvgThumbnailProvider.dll",
|
||||||
|
"PowerToys.SvgThumbnailProvider.exe",
|
||||||
|
"PowerToys.SvgThumbnailProviderCpp.dll",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.FileLocksmithLib.Interop.dll",
|
"WinUI3Apps\\PowerToys.HostsModuleInterface.dll",
|
||||||
"WinUI3Apps\\PowerToys.FileLocksmithExt.dll",
|
"WinUI3Apps\\PowerToys.HostsUILib.dll",
|
||||||
"WinUI3Apps\\PowerToys.FileLocksmithUI.exe",
|
"WinUI3Apps\\PowerToys.Hosts.dll",
|
||||||
"WinUI3Apps\\PowerToys.FileLocksmithUI.dll",
|
"WinUI3Apps\\PowerToys.Hosts.exe",
|
||||||
"WinUI3Apps\\PowerToys.FileLocksmithContextMenu.dll",
|
|
||||||
"FileLocksmithContextMenuPackage.msix",
|
|
||||||
|
|
||||||
"WinUI3Apps\\Peek.Common.dll",
|
"WinUI3Apps\\PowerToys.FileLocksmithLib.Interop.dll",
|
||||||
"WinUI3Apps\\Peek.FilePreviewer.dll",
|
"WinUI3Apps\\PowerToys.FileLocksmithExt.dll",
|
||||||
"WinUI3Apps\\Powertoys.Peek.UI.dll",
|
"WinUI3Apps\\PowerToys.FileLocksmithUI.exe",
|
||||||
"WinUI3Apps\\Powertoys.Peek.UI.exe",
|
"WinUI3Apps\\PowerToys.FileLocksmithUI.dll",
|
||||||
"WinUI3Apps\\Powertoys.Peek.dll",
|
"WinUI3Apps\\PowerToys.FileLocksmithContextMenu.dll",
|
||||||
|
"FileLocksmithContextMenuPackage.msix",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariablesModuleInterface.dll",
|
"WinUI3Apps\\Peek.Common.dll",
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariablesUILib.dll",
|
"WinUI3Apps\\Peek.FilePreviewer.dll",
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariables.dll",
|
"WinUI3Apps\\Powertoys.Peek.UI.dll",
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariables.exe",
|
"WinUI3Apps\\Powertoys.Peek.UI.exe",
|
||||||
|
"WinUI3Apps\\Powertoys.Peek.dll",
|
||||||
|
|
||||||
"PowerToys.ImageResizer.exe",
|
"WinUI3Apps\\PowerToys.EnvironmentVariablesModuleInterface.dll",
|
||||||
"PowerToys.ImageResizer.dll",
|
"WinUI3Apps\\PowerToys.EnvironmentVariablesUILib.dll",
|
||||||
"PowerToys.ImageResizerExt.dll",
|
"WinUI3Apps\\PowerToys.EnvironmentVariables.dll",
|
||||||
"PowerToys.ImageResizerContextMenu.dll",
|
"WinUI3Apps\\PowerToys.EnvironmentVariables.exe",
|
||||||
"ImageResizerContextMenuPackage.msix",
|
|
||||||
|
|
||||||
"PowerToys.KeyboardManager.dll",
|
"PowerToys.ImageResizer.exe",
|
||||||
"KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe",
|
"PowerToys.ImageResizer.dll",
|
||||||
"KeyboardManagerEngine\\PowerToys.KeyboardManagerEngine.exe",
|
"PowerToys.ImageResizerExt.dll",
|
||||||
"PowerToys.KeyboardManagerEditorLibraryWrapper.dll",
|
"PowerToys.ImageResizerContextMenu.dll",
|
||||||
|
"ImageResizerContextMenuPackage.msix",
|
||||||
|
|
||||||
"PowerToys.Launcher.dll",
|
"PowerToys.KeyboardManager.dll",
|
||||||
"PowerToys.PowerLauncher.dll",
|
"KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe",
|
||||||
"PowerToys.PowerLauncher.exe",
|
"KeyboardManagerEngine\\PowerToys.KeyboardManagerEngine.exe",
|
||||||
"PowerToys.PowerLauncher.Telemetry.dll",
|
"PowerToys.KeyboardManagerEditorLibraryWrapper.dll",
|
||||||
"Wox.dll",
|
|
||||||
"Wox.Infrastructure.dll",
|
|
||||||
"Wox.Plugin.dll",
|
|
||||||
"RunPlugins\\Calculator\\Microsoft.PowerToys.Run.Plugin.Calculator.dll",
|
|
||||||
"RunPlugins\\Folder\\Microsoft.Plugin.Folder.dll",
|
|
||||||
"RunPlugins\\Indexer\\Microsoft.Plugin.Indexer.dll",
|
|
||||||
"RunPlugins\\OneNote\\Microsoft.PowerToys.Run.Plugin.OneNote.dll",
|
|
||||||
"RunPlugins\\History\\Microsoft.PowerToys.Run.Plugin.History.dll",
|
|
||||||
"RunPlugins\\PowerToys\\Microsoft.PowerToys.Run.Plugin.PowerToys.dll",
|
|
||||||
"RunPlugins\\Program\\Microsoft.Plugin.Program.dll",
|
|
||||||
"RunPlugins\\Registry\\Microsoft.PowerToys.Run.Plugin.Registry.dll",
|
|
||||||
"RunPlugins\\WindowsSettings\\Microsoft.PowerToys.Run.Plugin.WindowsSettings.dll",
|
|
||||||
"RunPlugins\\Shell\\Microsoft.Plugin.Shell.dll",
|
|
||||||
"RunPlugins\\Uri\\Microsoft.Plugin.Uri.dll",
|
|
||||||
"RunPlugins\\WindowWalker\\Microsoft.Plugin.WindowWalker.dll",
|
|
||||||
"RunPlugins\\UnitConverter\\Community.PowerToys.Run.Plugin.UnitConverter.dll",
|
|
||||||
"RunPlugins\\VSCodeWorkspaces\\Community.PowerToys.Run.Plugin.VSCodeWorkspaces.dll",
|
|
||||||
"RunPlugins\\Service\\Microsoft.PowerToys.Run.Plugin.Service.dll",
|
|
||||||
"RunPlugins\\System\\Microsoft.PowerToys.Run.Plugin.System.dll",
|
|
||||||
"RunPlugins\\TimeDate\\Microsoft.PowerToys.Run.Plugin.TimeDate.dll",
|
|
||||||
"RunPlugins\\ValueGenerator\\Community.PowerToys.Run.Plugin.ValueGenerator.dll",
|
|
||||||
"RunPlugins\\WebSearch\\Community.PowerToys.Run.Plugin.WebSearch.dll",
|
|
||||||
"RunPlugins\\WindowsTerminal\\Microsoft.PowerToys.Run.Plugin.WindowsTerminal.dll",
|
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.MeasureToolModuleInterface.dll",
|
|
||||||
"WinUI3Apps\\PowerToys.MeasureToolCore.dll",
|
|
||||||
"WinUI3Apps\\PowerToys.MeasureToolUI.dll",
|
|
||||||
"WinUI3Apps\\PowerToys.MeasureToolUI.exe",
|
|
||||||
|
|
||||||
"PowerToys.FindMyMouse.dll",
|
"PowerToys.Launcher.dll",
|
||||||
"PowerToys.MouseHighlighter.dll",
|
"PowerToys.PowerLauncher.dll",
|
||||||
"PowerToys.MouseJump.dll",
|
"PowerToys.PowerLauncher.exe",
|
||||||
"PowerToys.MouseJump.Common.dll",
|
"PowerToys.PowerLauncher.Telemetry.dll",
|
||||||
"PowerToys.MousePointerCrosshairs.dll",
|
"Wox.dll",
|
||||||
"PowerToys.MouseJumpUI.dll",
|
"Wox.Infrastructure.dll",
|
||||||
"PowerToys.MouseJumpUI.exe",
|
"Wox.Plugin.dll",
|
||||||
|
"RunPlugins\\Calculator\\Microsoft.PowerToys.Run.Plugin.Calculator.dll",
|
||||||
|
"RunPlugins\\Folder\\Microsoft.Plugin.Folder.dll",
|
||||||
|
"RunPlugins\\Indexer\\Microsoft.Plugin.Indexer.dll",
|
||||||
|
"RunPlugins\\OneNote\\Microsoft.PowerToys.Run.Plugin.OneNote.dll",
|
||||||
|
"RunPlugins\\History\\Microsoft.PowerToys.Run.Plugin.History.dll",
|
||||||
|
"RunPlugins\\PowerToys\\Microsoft.PowerToys.Run.Plugin.PowerToys.dll",
|
||||||
|
"RunPlugins\\Program\\Microsoft.Plugin.Program.dll",
|
||||||
|
"RunPlugins\\Registry\\Microsoft.PowerToys.Run.Plugin.Registry.dll",
|
||||||
|
"RunPlugins\\WindowsSettings\\Microsoft.PowerToys.Run.Plugin.WindowsSettings.dll",
|
||||||
|
"RunPlugins\\Shell\\Microsoft.Plugin.Shell.dll",
|
||||||
|
"RunPlugins\\Uri\\Microsoft.Plugin.Uri.dll",
|
||||||
|
"RunPlugins\\WindowWalker\\Microsoft.Plugin.WindowWalker.dll",
|
||||||
|
"RunPlugins\\UnitConverter\\Community.PowerToys.Run.Plugin.UnitConverter.dll",
|
||||||
|
"RunPlugins\\VSCodeWorkspaces\\Community.PowerToys.Run.Plugin.VSCodeWorkspaces.dll",
|
||||||
|
"RunPlugins\\Service\\Microsoft.PowerToys.Run.Plugin.Service.dll",
|
||||||
|
"RunPlugins\\System\\Microsoft.PowerToys.Run.Plugin.System.dll",
|
||||||
|
"RunPlugins\\TimeDate\\Microsoft.PowerToys.Run.Plugin.TimeDate.dll",
|
||||||
|
"RunPlugins\\ValueGenerator\\Community.PowerToys.Run.Plugin.ValueGenerator.dll",
|
||||||
|
"RunPlugins\\WebSearch\\Community.PowerToys.Run.Plugin.WebSearch.dll",
|
||||||
|
"RunPlugins\\WindowsTerminal\\Microsoft.PowerToys.Run.Plugin.WindowsTerminal.dll",
|
||||||
|
|
||||||
"PowerToys.MouseWithoutBorders.dll",
|
"WinUI3Apps\\PowerToys.MeasureToolModuleInterface.dll",
|
||||||
"PowerToys.MouseWithoutBorders.exe",
|
"WinUI3Apps\\PowerToys.MeasureToolCore.dll",
|
||||||
"PowerToys.MouseWithoutBordersModuleInterface.dll",
|
"WinUI3Apps\\PowerToys.MeasureToolUI.dll",
|
||||||
"PowerToys.MouseWithoutBordersService.dll",
|
"WinUI3Apps\\PowerToys.MeasureToolUI.exe",
|
||||||
"PowerToys.MouseWithoutBordersService.exe",
|
|
||||||
"PowerToys.MouseWithoutBordersHelper.dll",
|
|
||||||
"PowerToys.MouseWithoutBordersHelper.exe",
|
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.NewPlus.ShellExtension.dll",
|
"PowerToys.FindMyMouse.dll",
|
||||||
"WinUI3Apps\\NewPlusPackage.msix",
|
"PowerToys.MouseHighlighter.dll",
|
||||||
"WinUI3Apps\\PowerToys.NewPlus.ShellExtension.win10.dll",
|
"PowerToys.MouseJump.dll",
|
||||||
|
"PowerToys.MouseJump.Common.dll",
|
||||||
|
"PowerToys.MousePointerCrosshairs.dll",
|
||||||
|
"PowerToys.MouseJumpUI.dll",
|
||||||
|
"PowerToys.MouseJumpUI.exe",
|
||||||
|
|
||||||
"PowerAccent.Core.dll",
|
"PowerToys.MouseWithoutBorders.dll",
|
||||||
"PowerToys.PowerAccent.dll",
|
"PowerToys.MouseWithoutBorders.exe",
|
||||||
"PowerToys.PowerAccent.exe",
|
"PowerToys.MouseWithoutBordersModuleInterface.dll",
|
||||||
"PowerToys.PowerAccentModuleInterface.dll",
|
"PowerToys.MouseWithoutBordersService.dll",
|
||||||
"PowerToys.PowerAccentKeyboardService.dll",
|
"PowerToys.MouseWithoutBordersService.exe",
|
||||||
|
"PowerToys.MouseWithoutBordersHelper.dll",
|
||||||
|
"PowerToys.MouseWithoutBordersHelper.exe",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.PowerRenameExt.dll",
|
"WinUI3Apps\\PowerToys.NewPlus.ShellExtension.dll",
|
||||||
"WinUI3Apps\\PowerToys.PowerRename.exe",
|
"WinUI3Apps\\NewPlusPackage.msix",
|
||||||
"WinUI3Apps\\PowerToys.PowerRenameContextMenu.dll",
|
"WinUI3Apps\\PowerToys.NewPlus.ShellExtension.win10.dll",
|
||||||
"WinUI3Apps\\PowerRenameContextMenuPackage.msix",
|
|
||||||
|
|
||||||
"PowerToys.WorkspacesSnapshotTool.exe",
|
"PowerAccent.Core.dll",
|
||||||
"PowerToys.WorkspacesLauncher.exe",
|
"PowerToys.PowerAccent.dll",
|
||||||
"PowerToys.WorkspacesWindowArranger.exe",
|
"PowerToys.PowerAccent.exe",
|
||||||
"PowerToys.WorkspacesEditor.exe",
|
"PowerToys.PowerAccentModuleInterface.dll",
|
||||||
"PowerToys.WorkspacesEditor.dll",
|
"PowerToys.PowerAccentKeyboardService.dll",
|
||||||
"PowerToys.WorkspacesLauncherUI.exe",
|
|
||||||
"PowerToys.WorkspacesLauncherUI.dll",
|
|
||||||
"PowerToys.WorkspacesModuleInterface.dll",
|
|
||||||
"PowerToys.WorkspacesCsharpLibrary.dll",
|
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreviewExt.dll",
|
"WinUI3Apps\\PowerToys.PowerRenameExt.dll",
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreviewUILib.dll",
|
"WinUI3Apps\\PowerToys.PowerRename.exe",
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreview.dll",
|
"WinUI3Apps\\PowerToys.PowerRenameContextMenu.dll",
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreview.exe",
|
"WinUI3Apps\\PowerRenameContextMenuPackage.msix",
|
||||||
|
|
||||||
"PowerToys.ShortcutGuide.exe",
|
"PowerToys.WorkspacesSnapshotTool.exe",
|
||||||
"PowerToys.ShortcutGuideModuleInterface.dll",
|
"PowerToys.WorkspacesLauncher.exe",
|
||||||
|
"PowerToys.WorkspacesWindowArranger.exe",
|
||||||
|
"PowerToys.WorkspacesEditor.exe",
|
||||||
|
"PowerToys.WorkspacesEditor.dll",
|
||||||
|
"PowerToys.WorkspacesLauncherUI.exe",
|
||||||
|
"PowerToys.WorkspacesLauncherUI.dll",
|
||||||
|
"PowerToys.WorkspacesModuleInterface.dll",
|
||||||
|
"PowerToys.WorkspacesCsharpLibrary.dll",
|
||||||
|
|
||||||
"PowerToys.ZoomIt.exe",
|
"WinUI3Apps\\PowerToys.RegistryPreviewExt.dll",
|
||||||
"PowerToys.ZoomItModuleInterface.dll",
|
"WinUI3Apps\\PowerToys.RegistryPreviewUILib.dll",
|
||||||
"PowerToys.ZoomItSettingsInterop.dll",
|
"WinUI3Apps\\PowerToys.RegistryPreview.dll",
|
||||||
|
"WinUI3Apps\\PowerToys.RegistryPreview.exe",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.Settings.dll",
|
"PowerToys.ShortcutGuide.exe",
|
||||||
"WinUI3Apps\\PowerToys.Settings.exe",
|
"PowerToys.ShortcutGuideModuleInterface.dll",
|
||||||
|
|
||||||
"PowerToys.CmdPalModuleInterface.dll",
|
"PowerToys.ZoomIt.exe",
|
||||||
"CmdPalKeyboardService.dll",
|
"PowerToys.ZoomItModuleInterface.dll",
|
||||||
"*Microsoft.CmdPal.UI_*.msix"
|
"PowerToys.ZoomItSettingsInterop.dll",
|
||||||
],
|
|
||||||
|
"WinUI3Apps\\PowerToys.Settings.dll",
|
||||||
|
"WinUI3Apps\\PowerToys.Settings.exe",
|
||||||
|
|
||||||
|
"PowerToys.CmdPalModuleInterface.dll",
|
||||||
|
"CmdPalKeyboardService.dll",
|
||||||
|
"*Microsoft.CmdPal.UI_*.msix"
|
||||||
|
],
|
||||||
"SigningInfo": {
|
"SigningInfo": {
|
||||||
"Operations": [
|
"Operations": [
|
||||||
{
|
{
|
||||||
|
|||||||
37
NOTICE.md
37
NOTICE.md
@@ -79,6 +79,43 @@ For more information, please refer to <http://unlicense.org/>
|
|||||||
|
|
||||||
### Calculator
|
### Calculator
|
||||||
|
|
||||||
|
#### exprtk
|
||||||
|
|
||||||
|
We use the exprtk library (exprtk.hpp) to evaluate mathematical expressions.
|
||||||
|
|
||||||
|
**Source**: [https://github.com/ArashPartow/exprtk](https://github.com/ArashPartow/exprtk)
|
||||||
|
|
||||||
|
```
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 1999-2024 Arash Partow
|
||||||
|
|
||||||
|
https://www.partow.net/programming/exprtk/index.html
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Utility: PowerToys Run Built-in Extensions
|
||||||
|
|
||||||
|
### Calculator
|
||||||
|
|
||||||
#### Mages
|
#### Mages
|
||||||
|
|
||||||
We use the Mages NuGet package for calculating the result of expression.
|
We use the Mages NuGet package for calculating the result of expression.
|
||||||
|
|||||||
@@ -717,6 +717,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CmdPalKeyboardService", "sr
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRename.FuzzingTest", "src\modules\powerrename\PowerRename.FuzzingTest\PowerRename.FuzzingTest.vcxproj", "{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRename.FuzzingTest", "src\modules\powerrename\PowerRename.FuzzingTest\PowerRename.FuzzingTest.vcxproj", "{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalculatorEngineCommon", "src\common\CalculatorEngineCommon\CalculatorEngineCommon.vcxproj", "{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|ARM64 = Debug|ARM64
|
Debug|ARM64 = Debug|ARM64
|
||||||
@@ -2619,6 +2621,14 @@ Global
|
|||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|ARM64.ActiveCfg = Release|ARM64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.ActiveCfg = Release|x64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.ActiveCfg = Release|x64
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.Build.0 = Release|x64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -2893,6 +2903,7 @@ Global
|
|||||||
{0217E86E-3476-9946-DE8E-9D200CEBD47A} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
||||||
{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2} = {3846508C-77EB-4034-A702-F8BB263C4F79}
|
{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2} = {3846508C-77EB-4034-A702-F8BB263C4F79}
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
|
||||||
|
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||||
|
|||||||
24
src/common/CalculatorEngineCommon/Calculator.cpp
Normal file
24
src/common/CalculatorEngineCommon/Calculator.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "Calculator.h"
|
||||||
|
#include "Calculator.g.cpp"
|
||||||
|
#include "ExprtkEvaluator.h"
|
||||||
|
|
||||||
|
namespace winrt::CalculatorEngineCommon::implementation
|
||||||
|
{
|
||||||
|
Calculator::Calculator(winrt::Windows::Foundation::Collections::IPropertySet const& constants)
|
||||||
|
{
|
||||||
|
for (auto const& pair : constants)
|
||||||
|
{
|
||||||
|
auto key = pair.Key();
|
||||||
|
auto value = winrt::unbox_value<double>(pair.Value());
|
||||||
|
m_constants.emplace(winrt::to_string(key), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hstring Calculator::EvaluateExpression(hstring const& expression)
|
||||||
|
{
|
||||||
|
auto result = ExprtkCalculator::internal::EvaluateExpression(winrt::to_string(expression), m_constants);
|
||||||
|
|
||||||
|
return hstring(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/common/CalculatorEngineCommon/Calculator.h
Normal file
25
src/common/CalculatorEngineCommon/Calculator.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Calculator.g.h"
|
||||||
|
|
||||||
|
namespace winrt::CalculatorEngineCommon::implementation
|
||||||
|
{
|
||||||
|
struct Calculator : CalculatorT<Calculator>
|
||||||
|
{
|
||||||
|
Calculator() = default;
|
||||||
|
|
||||||
|
Calculator(winrt::Windows::Foundation::Collections::IPropertySet const& constants);
|
||||||
|
|
||||||
|
winrt::hstring EvaluateExpression(winrt::hstring const& expression);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, double> m_constants;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace winrt::CalculatorEngineCommon::factory_implementation
|
||||||
|
{
|
||||||
|
struct Calculator : CalculatorT<Calculator, implementation::Calculator>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
10
src/common/CalculatorEngineCommon/Calculator.idl
Normal file
10
src/common/CalculatorEngineCommon/Calculator.idl
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace CalculatorEngineCommon
|
||||||
|
{
|
||||||
|
[default_interface]
|
||||||
|
runtimeclass Calculator
|
||||||
|
{
|
||||||
|
Calculator();
|
||||||
|
Calculator(Windows.Foundation.Collections.IPropertySet constants);
|
||||||
|
String EvaluateExpression(String expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
EXPORTS
|
||||||
|
DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
|
||||||
|
DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
|
||||||
181
src/common/CalculatorEngineCommon/CalculatorEngineCommon.vcxproj
Normal file
181
src/common/CalculatorEngineCommon/CalculatorEngineCommon.vcxproj
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
|
||||||
|
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
|
||||||
|
<ProjectGuid>{2cf78cf7-8feb-4be1-9591-55fa25b48fc6}</ProjectGuid>
|
||||||
|
<ProjectName>CalculatorEngineCommon</ProjectName>
|
||||||
|
<RootNamespace>CalculatorEngineCommon</RootNamespace>
|
||||||
|
<AppxPackage>false</AppxPackage>
|
||||||
|
</PropertyGroup>
|
||||||
|
<!-- BEGIN common.build.pre.props -->
|
||||||
|
<PropertyGroup Label="Configuration">
|
||||||
|
<EnableHybridCRT>true</EnableHybridCRT>
|
||||||
|
<UseCrtSDKReferenceStaticWarning Condition="'$(EnableHybridCRT)'=='true'">false</UseCrtSDKReferenceStaticWarning>
|
||||||
|
</PropertyGroup>
|
||||||
|
<!-- END common.build.pre.props -->
|
||||||
|
<!-- BEGIN cppwinrt.build.pre.props -->
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<CppWinRTEnabled>true</CppWinRTEnabled>
|
||||||
|
<CppWinRTOptimized>true</CppWinRTOptimized>
|
||||||
|
<DefaultLanguage>en-US</DefaultLanguage>
|
||||||
|
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
|
||||||
|
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<MinimalCoreWin>true</MinimalCoreWin>
|
||||||
|
<AppContainerApplication>true</AppContainerApplication>
|
||||||
|
<WindowsStoreApp>true</WindowsStoreApp>
|
||||||
|
<ApplicationType>Windows Store</ApplicationType>
|
||||||
|
<UseCrtSDKReference Condition="'$(EnableHybridCRT)'=='true'">false</UseCrtSDKReference>
|
||||||
|
<!-- The SDK reference breaks the Hybrid CRT -->
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- We have to use the Desktop platform for Hybrid CRT to work. -->
|
||||||
|
<_VC_Target_Library_Platform>Desktop</_VC_Target_Library_Platform>
|
||||||
|
<_NoWinAPIFamilyApp>true</_NoWinAPIFamilyApp>
|
||||||
|
</PropertyGroup>
|
||||||
|
<!-- END cppwinrt.build.pre.props -->
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<GenerateManifest>false</GenerateManifest>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets">
|
||||||
|
<Import Project="PropertySheet.props" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetName>CalculatorEngineCommon</TargetName>
|
||||||
|
<OutDir>..\..\..\$(Platform)\$(Configuration)\</OutDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup>
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
|
||||||
|
<PreprocessorDefinitions>_WINRT_DLL;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<AdditionalIncludeDirectories>../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
|
||||||
|
<ModuleDefinitionFile>CalculatorEngineCommon.def</ModuleDefinitionFile>
|
||||||
|
<AdditionalDependencies>Shell32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="ExprtkEvaluator.h" />
|
||||||
|
<ClInclude Include="pch.h" />
|
||||||
|
<ClInclude Include="exprtk.hpp" />
|
||||||
|
<ClInclude Include="Calculator.h">
|
||||||
|
<DependentUpon>Calculator.idl</DependentUpon>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="ExprtkEvaluator.cpp">
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="pch.cpp">
|
||||||
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Calculator.cpp">
|
||||||
|
<DependentUpon>Calculator.idl</DependentUpon>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Midl Include="Calculator.idl" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
<None Include="CalculatorEngineCommon.def" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="PropertySheet.props" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<Import Project="..\..\..\deps\spdlog.props" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
<Import Project="..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||||
|
</ImportGroup>
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||||
|
<Error Condition="!Exists('..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||||
|
</Target>
|
||||||
|
<!-- BEGIN common.build.post.props -->
|
||||||
|
<!--
|
||||||
|
The Hybrid CRT model statically links the runtime and STL and dynamically
|
||||||
|
links the UCRT instead of the VC++ CRT. The UCRT ships with Windows.
|
||||||
|
WinAppSDK asserts that this is "supported according to the CRT maintainer."
|
||||||
|
|
||||||
|
This must come before Microsoft.Cpp.targets because it manipulates ClCompile.RuntimeLibrary.
|
||||||
|
-->
|
||||||
|
<ItemDefinitionGroup Condition="'$(EnableHybridCRT)'=='true' and '$(Configuration)'=='Debug'">
|
||||||
|
<ClCompile>
|
||||||
|
<!-- We use MultiThreadedDebug, rather than MultiThreadedDebugDLL, to avoid DLL dependencies on VCRUNTIME140d.dll and MSVCP140d.dll. -->
|
||||||
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
|
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<!-- Link statically against the runtime and STL, but link dynamically against the CRT by ignoring the static CRT
|
||||||
|
lib and instead linking against the Universal CRT DLL import library. This "hybrid" linking mechanism is
|
||||||
|
supported according to the CRT maintainer. Dynamic linking against the CRT makes the binaries a bit smaller
|
||||||
|
than they would otherwise be if the CRT, runtime, and STL were all statically linked in. -->
|
||||||
|
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries);libucrtd.lib</IgnoreSpecificDefaultLibraries>
|
||||||
|
<AdditionalOptions>%(AdditionalOptions) /defaultlib:ucrtd.lib</AdditionalOptions>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(EnableHybridCRT)'=='true' and ('$(Configuration)'=='Release' or '$(Configuration)'=='AuditMode')">
|
||||||
|
<ClCompile>
|
||||||
|
<!-- We use MultiThreaded, rather than MultiThreadedDLL, to avoid DLL dependencies on VCRUNTIME140.dll and MSVCP140.dll. -->
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<!-- Link statically against the runtime and STL, but link dynamically against the CRT by ignoring the static CRT
|
||||||
|
lib and instead linking against the Universal CRT DLL import library. This "hybrid" linking mechanism is
|
||||||
|
supported according to the CRT maintainer. Dynamic linking against the CRT makes the binaries a bit smaller
|
||||||
|
than they would otherwise be if the CRT, runtime, and STL were all statically linked in. -->
|
||||||
|
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries);libucrt.lib</IgnoreSpecificDefaultLibraries>
|
||||||
|
<AdditionalOptions>%(AdditionalOptions) /defaultlib:ucrt.lib</AdditionalOptions>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<!-- END common.build.post.props -->
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Resources">
|
||||||
|
<UniqueIdentifier>accd3aa8-1ba0-4223-9bbe-0c431709210b</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Generated Files">
|
||||||
|
<UniqueIdentifier>{926ab91d-31b4-48c3-b9a4-e681349f27f0}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="pch.cpp" />
|
||||||
|
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="pch.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Midl Include="Calculator.idl" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="CalculatorEngineCommon.def" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="PropertySheet.props" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
50
src/common/CalculatorEngineCommon/ExprtkEvaluator.cpp
Normal file
50
src/common/CalculatorEngineCommon/ExprtkEvaluator.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "ExprtkEvaluator.h"
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace ExprtkCalculator::internal
|
||||||
|
{
|
||||||
|
|
||||||
|
std::wstring ToWStringFullPrecision(double value)
|
||||||
|
{
|
||||||
|
std::wostringstream oss;
|
||||||
|
oss << std::fixed << std::setprecision(15) << value;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring EvaluateExpression(
|
||||||
|
const std::string& expressionText,
|
||||||
|
const std::unordered_map<std::string, double>& constants)
|
||||||
|
{
|
||||||
|
exprtk::symbol_table<double> symbol_table;
|
||||||
|
|
||||||
|
for (auto const& [name, value] : constants)
|
||||||
|
{
|
||||||
|
symbol_table.add_constant(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
exprtk::expression<double> expression;
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
exprtk::parser<double> parser;
|
||||||
|
|
||||||
|
// Enable all base functions and arithmetic operators
|
||||||
|
parser.settings().enable_all_base_functions(); // Enable all base functions like sin, cos, log, etc.
|
||||||
|
parser.settings().enable_all_arithmetic_ops(); // Enable all arithmetic operators like +, -, *, /, etc.
|
||||||
|
|
||||||
|
// Disable all control structures and assignment operators to ensure only expressions are evaluated
|
||||||
|
parser.settings().disable_all_control_structures(); // Disable control structures like if, for, while, etc.
|
||||||
|
parser.settings().disable_all_assignment_ops(); // Disable assignment operators like =, +=, -=, etc.
|
||||||
|
|
||||||
|
// Disabled for now, but can be enabled later for enhanced functionality
|
||||||
|
parser.settings().disable_all_logic_ops(); // Disable logical operators like &&, ||, !, etc.
|
||||||
|
parser.settings().disable_all_inequality_ops(); // Disable inequality operators like <, >, <=, >=, !=, etc.
|
||||||
|
|
||||||
|
if (!parser.compile(expressionText, expression))
|
||||||
|
return L"NaN";
|
||||||
|
|
||||||
|
return ToWStringFullPrecision(expression.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/common/CalculatorEngineCommon/ExprtkEvaluator.h
Normal file
10
src/common/CalculatorEngineCommon/ExprtkEvaluator.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace ExprtkCalculator::internal
|
||||||
|
{
|
||||||
|
std::wstring EvaluateExpression(
|
||||||
|
const std::string& expression,
|
||||||
|
const std::unordered_map<std::string, double>& constants);
|
||||||
|
}
|
||||||
16
src/common/CalculatorEngineCommon/PropertySheet.props
Normal file
16
src/common/CalculatorEngineCommon/PropertySheet.props
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ImportGroup Label="PropertySheets" />
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<!--
|
||||||
|
To customize common C++/WinRT project properties:
|
||||||
|
* right-click the project node
|
||||||
|
* expand the Common Properties item
|
||||||
|
* select the C++/WinRT property page
|
||||||
|
|
||||||
|
For more advanced scenarios, and complete documentation, please see:
|
||||||
|
https://github.com/Microsoft/cppwinrt/tree/master/nuget
|
||||||
|
-->
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemDefinitionGroup />
|
||||||
|
</Project>
|
||||||
46251
src/common/CalculatorEngineCommon/exprtk.hpp
Normal file
46251
src/common/CalculatorEngineCommon/exprtk.hpp
Normal file
File diff suppressed because it is too large
Load Diff
4
src/common/CalculatorEngineCommon/packages.config
Normal file
4
src/common/CalculatorEngineCommon/packages.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
|
||||||
|
</packages>
|
||||||
1
src/common/CalculatorEngineCommon/pch.cpp
Normal file
1
src/common/CalculatorEngineCommon/pch.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "pch.h"
|
||||||
4
src/common/CalculatorEngineCommon/pch.h
Normal file
4
src/common/CalculatorEngineCommon/pch.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <unknwn.h>
|
||||||
|
#include <winrt/Windows.Foundation.h>
|
||||||
|
#include <winrt/Windows.Foundation.Collections.h>
|
||||||
29
src/common/CalculatorEngineCommon/readme.md
Normal file
29
src/common/CalculatorEngineCommon/readme.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# C++/WinRT CalculatorEngine Project Overview
|
||||||
|
|
||||||
|
This project wraps the exprtk expression parsing library with a C++/WinRT component,
|
||||||
|
making advanced mathematical evaluation capabilities available to Windows applications.
|
||||||
|
It is designed specifically to provide calculation support for the CmdPal calculator extension.
|
||||||
|
|
||||||
|
## Using exprtk
|
||||||
|
|
||||||
|
This project uses [exprtk](https://github.com/ArashPartow/exprtk) as the
|
||||||
|
expression parsing and evaluation engine.
|
||||||
|
|
||||||
|
How to use exprtk in this project:
|
||||||
|
- The exprtk header file (`exprtk.hpp`) is included in the project source.
|
||||||
|
- You can use exprtk to parse and evaluate mathematical expressions in your
|
||||||
|
C++ code. For example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
exprtk::expression<double> expression;
|
||||||
|
exprtk::parser<double> parser;
|
||||||
|
std::string formula = "3 + 4 * 2";
|
||||||
|
parser.compile(formula, expression);
|
||||||
|
double result = expression.value();
|
||||||
|
```
|
||||||
|
|
||||||
|
How to update exprtk:
|
||||||
|
1. Download the latest `exprtk.hpp` from the [official repository](https://github.com/ArashPartow/exprtk).
|
||||||
|
2. Replace the existing `exprtk.hpp` file in the project with the new version.
|
||||||
|
3. Rebuild the project to ensure compatibility and take advantage of any updates.
|
||||||
@@ -6,20 +6,20 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using CalculatorEngineCommon;
|
||||||
using Mages.Core;
|
using Windows.Foundation.Collections;
|
||||||
|
|
||||||
namespace Microsoft.CmdPal.Ext.Calc.Helper;
|
namespace Microsoft.CmdPal.Ext.Calc.Helper;
|
||||||
|
|
||||||
public static class CalculateEngine
|
public static class CalculateEngine
|
||||||
{
|
{
|
||||||
private static readonly Engine _magesEngine = new Engine(new Configuration
|
private static readonly PropertySet _constants = new()
|
||||||
{
|
{
|
||||||
Scope = new Dictionary<string, object>
|
{ "pi", Math.PI },
|
||||||
{
|
{ "e", Math.E },
|
||||||
{ "e", Math.E }, // e is not contained in the default mages engine
|
};
|
||||||
},
|
|
||||||
});
|
private static readonly Calculator _calculator = new Calculator(_constants);
|
||||||
|
|
||||||
public const int RoundingDigits = 10;
|
public const int RoundingDigits = 10;
|
||||||
|
|
||||||
@@ -68,28 +68,26 @@ public static class CalculateEngine
|
|||||||
// Expand conversions between trig units
|
// Expand conversions between trig units
|
||||||
input = CalculateHelper.ExpandTrigConversions(input, trigMode);
|
input = CalculateHelper.ExpandTrigConversions(input, trigMode);
|
||||||
|
|
||||||
var result = _magesEngine.Interpret(input);
|
var result = _calculator.EvaluateExpression(input);
|
||||||
|
|
||||||
// This could happen for some incorrect queries, like pi(2)
|
// This could happen for some incorrect queries, like pi(2)
|
||||||
if (result == null)
|
if (result == "NaN")
|
||||||
{
|
{
|
||||||
error = Properties.Resources.calculator_expression_not_complete;
|
error = Properties.Resources.calculator_expression_not_complete;
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = TransformResult(result);
|
if (string.IsNullOrEmpty(result))
|
||||||
if (result is string)
|
|
||||||
{
|
|
||||||
error = result as string;
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(result?.ToString()))
|
|
||||||
{
|
{
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
var decimalResult = Convert.ToDecimal(result, cultureInfo);
|
var decimalResult = Convert.ToDecimal(result, cultureInfo);
|
||||||
|
|
||||||
|
// Remove trailing zeros from the decimal string representation (e.g., "1.2300" -> "1.23")
|
||||||
|
// This is necessary because the value extracted from exprtk may contain unnecessary trailing zeros.
|
||||||
|
var formatted = decimalResult.ToString("G29", cultureInfo);
|
||||||
|
decimalResult = Convert.ToDecimal(formatted, cultureInfo);
|
||||||
var roundedResult = Round(decimalResult);
|
var roundedResult = Round(decimalResult);
|
||||||
|
|
||||||
return new CalculateResult()
|
return new CalculateResult()
|
||||||
@@ -103,25 +101,4 @@ public static class CalculateEngine
|
|||||||
{
|
{
|
||||||
return Math.Round(value, RoundingDigits, MidpointRounding.AwayFromZero);
|
return Math.Round(value, RoundingDigits, MidpointRounding.AwayFromZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static dynamic TransformResult(object result)
|
|
||||||
{
|
|
||||||
if (result.ToString() == "NaN")
|
|
||||||
{
|
|
||||||
return Properties.Resources.calculator_not_a_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result is Function)
|
|
||||||
{
|
|
||||||
return Properties.Resources.calculator_expression_not_complete;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result is double[,])
|
|
||||||
{
|
|
||||||
// '[10,10]' is interpreted as array by mages engine
|
|
||||||
return Properties.Resources.calculator_double_array_returned;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -63,46 +64,61 @@ public class NumberTranslator
|
|||||||
return Translate(input, targetCulture, sourceCulture, splitRegexForTarget);
|
return Translate(input, targetCulture, sourceCulture, splitRegexForTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ConvertBaseLiteral(string token, CultureInfo cultureTo)
|
||||||
|
{
|
||||||
|
var prefixes = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "0x", 16 },
|
||||||
|
{ "0b", 2 },
|
||||||
|
{ "0o", 8 },
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var (prefix, numberBase) in prefixes)
|
||||||
|
{
|
||||||
|
if (token.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var num = Convert.ToInt64(token.Substring(prefix.Length), numberBase);
|
||||||
|
return num.ToString(cultureTo);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null; // fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static string Translate(string input, CultureInfo cultureFrom, CultureInfo cultureTo, Regex splitRegex)
|
private static string Translate(string input, CultureInfo cultureFrom, CultureInfo cultureTo, Regex splitRegex)
|
||||||
{
|
{
|
||||||
var outputBuilder = new StringBuilder();
|
var outputBuilder = new StringBuilder();
|
||||||
var hexRegex = new Regex(@"(?:(0x[\da-fA-F]+))");
|
|
||||||
|
|
||||||
var hexTokens = hexRegex.Split(input);
|
// Match numbers in hexadecimal (0x..), binary (0b..), or octal (0o..) format,
|
||||||
|
// and convert them to decimal form for compatibility with ExprTk (which only supports decimal input).
|
||||||
|
var baseNumberRegex = new Regex(@"(0[xX][\da-fA-F]+|0[bB][0-9]+|0[oO][0-9]+)");
|
||||||
|
|
||||||
foreach (var hexToken in hexTokens)
|
var tokens = baseNumberRegex.Split(input);
|
||||||
|
|
||||||
|
foreach (var token in tokens)
|
||||||
{
|
{
|
||||||
if (hexToken.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
|
// Currently, we only convert base literals (hexadecimal, binary, octal) to decimal.
|
||||||
{
|
var converted = ConvertBaseLiteral(token, cultureTo);
|
||||||
// Mages engine has issues processing large hex number (larger than 7 hex digits + 0x prefix = 9 characters). So we convert it to decimal and pass it to the engine.
|
|
||||||
if (hexToken.Length > 9)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var num = Convert.ToInt64(hexToken, 16);
|
|
||||||
var numStr = num.ToString(cultureFrom);
|
|
||||||
outputBuilder.Append(numStr);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
outputBuilder.Append(hexToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outputBuilder.Append(hexToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (converted != null)
|
||||||
|
{
|
||||||
|
outputBuilder.Append(converted);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tokens = splitRegex.Split(hexToken);
|
foreach (var inner in splitRegex.Split(token))
|
||||||
foreach (var token in tokens)
|
|
||||||
{
|
{
|
||||||
var leadingZeroCount = 0;
|
var leadingZeroCount = 0;
|
||||||
|
|
||||||
// Count leading zero characters.
|
// Count leading zero characters.
|
||||||
foreach (var c in token)
|
foreach (var c in inner)
|
||||||
{
|
{
|
||||||
if (c != '0')
|
if (c != '0')
|
||||||
{
|
{
|
||||||
@@ -113,7 +129,7 @@ public class NumberTranslator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// number is all zero characters. no need to add zero characters at the end.
|
// number is all zero characters. no need to add zero characters at the end.
|
||||||
if (token.Length == leadingZeroCount)
|
if (inner.Length == leadingZeroCount)
|
||||||
{
|
{
|
||||||
leadingZeroCount = 0;
|
leadingZeroCount = 0;
|
||||||
}
|
}
|
||||||
@@ -121,9 +137,9 @@ public class NumberTranslator
|
|||||||
decimal number;
|
decimal number;
|
||||||
|
|
||||||
outputBuilder.Append(
|
outputBuilder.Append(
|
||||||
decimal.TryParse(token, NumberStyles.Number, cultureFrom, out number)
|
decimal.TryParse(inner, NumberStyles.Number, cultureFrom, out number)
|
||||||
? (new string('0', leadingZeroCount) + number.ToString(cultureTo))
|
? (new string('0', leadingZeroCount) + number.ToString(cultureTo))
|
||||||
: token.Replace(cultureFrom.TextInfo.ListSeparator, cultureTo.TextInfo.ListSeparator));
|
: inner.Replace(cultureFrom.TextInfo.ListSeparator, cultureTo.TextInfo.ListSeparator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,11 +65,6 @@ public static partial class QueryHelper
|
|||||||
|
|
||||||
return ResultHelper.CreateResult(result.RoundedResult, inputCulture, outputCulture, query, handleSave);
|
return ResultHelper.CreateResult(result.RoundedResult, inputCulture, outputCulture, query, handleSave);
|
||||||
}
|
}
|
||||||
catch (Mages.Core.ParseException)
|
|
||||||
{
|
|
||||||
// Invalid input
|
|
||||||
return ErrorHandler.OnError(isFallbackSearch, query, Properties.Resources.calculator_expression_not_complete);
|
|
||||||
}
|
|
||||||
catch (OverflowException)
|
catch (OverflowException)
|
||||||
{
|
{
|
||||||
// Result to big to convert to decimal
|
// Result to big to convert to decimal
|
||||||
|
|||||||
@@ -9,15 +9,25 @@
|
|||||||
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
<ProjectPriFileName>Microsoft.CmdPal.Ext.Calc.pri</ProjectPriFileName>
|
<ProjectPriFileName>Microsoft.CmdPal.Ext.Calc.pri</ProjectPriFileName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<CsWinRTIncludes>CalculatorEngineCommon</CsWinRTIncludes>
|
||||||
|
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\..\common\CalculatorEngineCommon\CalculatorEngineCommon.vcxproj" />
|
||||||
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mages" />
|
<CsWinRTInputs Include="..\..\..\..\..\$(Platform)\$(Configuration)\CalculatorEngineCommon.winmd" />
|
||||||
|
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\CalculatorEngineCommon.winmd" Link="CalculatorEngineCommon.winmd">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\CalculatorEngineCommon.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
|||||||
Reference in New Issue
Block a user