|
I'm trying to manipulate XPS files in C# like this but I'm having a really weird problem. The original VS project works fine for me, but I've tried to modify it so I can either run it from powershell or so I can run it as a console application and in both cases on the output from the file I'm testing it on, only the first page of the output file works in the XPS viewer, but I don't get any error messages. Here is my last attempt to make it into a console application while modifying it as little as possible to try to figure out where the problem is (note the hardcoded paths partway down): http://pastebin.com/qmDik1b5 I've tried targeting different .net versions but even with .net 4.5 / x86 like in the demo program I can't get it to work. Am I missing something really obvious here? Also it's really lame that there seems to be no sane way to modify XPS files. You can open them and read them using the not-quite-so-lovely WPF interface, but there isn't any way to copy content from them without messing around with XML (you can't just copy the child elements on each fixedpage because they reference other resources like fonts in the original archive). It seems like you should be able to be able to open XPS files and just change some stuff before saving it again, but it seems like you aren't actually able to do that. It's frustrating because I was able to extract the text from an xps file in a few lines of powershell code, and it seemed like it would be just as easy to make some changes, but boy was I wrong. Edit: Rather than modifying the XPS file, is there any other easy way to manipulate the content and then display it? I tried modifying the fixeddocument in memory and then passing it to a DocumentViewer control but that didn't really work either (it sort of worked sporadically, but I think that's unintended behavior); is there some way I can render a single fixedpage to a window at a time and then be able to modify it? mystes fucked around with this message at 23:43 on May 21, 2016 |
# ¿ May 21, 2016 23:33 |
|
|
# ¿ May 3, 2024 14:42 |
|
mystes posted:I'm trying to manipulate XPS files in C# All that said, I realized that while the approach of modifying the document as xml is unavoidable, it could be much simpler than the c# example I was looking at if rather than building a new package file, I simply *copied* the original XPS file and modified it in place. This avoids the need to copy the parts from one package to another. Here is a simple example of turning all the text red in powershell: code:
It would be so much easier if it was actually possible to render a fixedpage to a visual and then use the normal api for generating an XPS file again. Edit: It turns out the font name is actually preserved in the obfuscated file (although you have to deobfuscate it, write out to the filesystem as a ttf file, and examine it to get at it). This makes me think that I might be able to switch back to the approach of adding the existing fixedpage to a visual, and then just cleaning it up a little bit. mystes fucked around with this message at 17:09 on May 22, 2016 |
# ¿ May 22, 2016 15:24 |
|
OK, so I doubt anybody cares, but it turns out that if you want to render a page of an XPS file via WPF so you can manipulate it, it's actually not that complicated once you know what to do (it was a serious pain to work out the exact details, however). The key trick for the fonts is to open the XPS file as an XPSDocument and call the ToGlyphRun method on the Glyphs objects. Then you can access the GlyphTypeface, which will tell you the font family, so you can figure out what resource urls correspond to what fonts, if you want to use the system fonts. (Otherwise, you can deobfuscate the subsetted fonts from the font stream via the GlyphTypeface, so you could probably use a private font collection but that would be more complicated and if you're actually trying to edit the text it would be pretty pointless anyway). Then you can access the XPS file as a package to get the images. You could probably serialize the FixedPage from the XPSDocument directly, but right now what I'm doing is getting the XML out the package and then simply rewriting the font uris to the system fonts and the image uris in the ImageBrushes to extracted copies of the images. As far as I can tell, the fonts in glyphs and the images in ImageBrushes are the only two places where FixedPages actually reference resources in the XPS package, so if you just fix these two things, you can parse whatever's inside the FixedPage element in the XML as XAML and write it to a window. Anyway, all this was pretty dumb and my advice for anyone who needs to work with XPS files would be to convert them to PDFs and then use PDFBox which has an API that's only moderately annoying
|
# ¿ May 24, 2016 04:52 |
|
john donne posted:I wonder if there will ever be a good framework for building GUIs in .NET that isn't html-driven With .net core existing now, I'm hoping that someone will finish decent cross-platform .net QT bindings, which might well be the least lovely cross-platform option by default. It's amazing that there still isn't a decent cross-platform gui option for .net, but the gui framework options are limited in the first place, and .net certainly hasn't seemed like a realistic choice outside of windows until like 1 day ago. mystes fucked around with this message at 02:19 on Jun 29, 2016 |
# ¿ Jun 29, 2016 02:16 |
|
Mr Shiny Pants posted:Xamarin forms?
|
# ¿ Jun 29, 2016 13:47 |
|
BirdOfPlay posted:Does FileInfo.Attributes tell me only if the file is flagged as Read Only or will it be flagged as ReadOnly if the file directory is write-protected as well? If I uncheck "Read Only" for the file in Program Files, it's still write protected. I know this because I've tried using an unelevated hex editor on the file and cannot save changes because of lowered permissions.. mystes fucked around with this message at 02:13 on Jul 13, 2016 |
# ¿ Jul 13, 2016 01:57 |
|
Combat Pretzel posted:In an UWA, I want to use a Polyline for a linechart and use relative coordinates and use Stretch="Fill", so that I don't have to recalculate point coordinates every time when I resize or whatever. The issue however is that say if the points used for Y axis goes from 0.25 to 0.75, it'll normalize it and stretch it as much as possible instead of leaving 25% on top and bottom blank as the min/max Y coordinates of the points suggest. A cheap temporary fix right now is to draw a first segment from top to bottom. How can I do this properly, because the cheap fix leaves an artifact. mystes fucked around with this message at 23:02 on Jul 17, 2016 |
# ¿ Jul 17, 2016 22:56 |
|
amotea posted:I can't figure out what we as developers are supposed to get out of this... we have to jump through a metric poo poo ton of hoops to get our perfectly working desktop apps to become a UWP package or something? WPF applications run just fine on Windows 10 lol. Are they implying people want to run our boring industrial business app on their xbox?
|
# ¿ Jul 21, 2016 13:52 |
|
From the earlier discussion about combining Windows Forms and WPF, which direction is less horrible? I was trying to do something in a DataGridView in WPF and it was way too slow, so I switched to Windows Forms, but it would also be really convenient to be able to use a WPF RichTextBox so I don't have to deal with RTF or something like that. Edit: ElementHost is actually OK, right? So I should be able to keep the application as windows forms and just embed the WPF control without too much trouble?
|
# ¿ Aug 21, 2016 03:14 |
|
If I have one thread writing (only) to an array of integers (I assume this would cause problems with individually heap allocated objects) and one thread reading (only), can I get away with not doing any synchronization if I don't mind the results possibly getting out of date? If so, if a small amount of the time I want the writing thread to signal the reading thread (via a bufferblock or something) that a value has been updated but do want the value pulled from the array to be up to date, is there anything special I need to do to ensure this?
|
# ¿ Aug 22, 2016 21:37 |
|
raminasi posted:If you're looking for the lowest-effort solution to whatever your actual problem is, it's a BlockingCollection. I guess I could just set a really low timeout and use a default value in that case, but it just seems like then there's no point in using the blockingcollection. I'm also just curious because I have always carefully avoided threading whenever possible but now I'm interested in how it works. mystes fucked around with this message at 23:31 on Aug 22, 2016 |
# ¿ Aug 22, 2016 23:26 |
|
ljw1004 posted:Short answer: Yes.
|
# ¿ Aug 22, 2016 23:53 |
|
Inverness posted:I'd like to know more about your DataGridView issue. Were you using row virtualization?
|
# ¿ Aug 26, 2016 02:22 |
|
Cuntpunch posted:Eh, Silverlight was a late-to-the-party attempt to fight Flash. If it had shown up 5 years earlier it probably would have had some sticking power - but instead it was just too late to matter - Flash itself was already showing its age and being replaced by HTML5, etc, and then suddenly a "oh boy another plugin for rich web content!" shows up. Just old-school Microsoft lovely timing. mystes fucked around with this message at 02:35 on Sep 14, 2016 |
# ¿ Sep 14, 2016 02:32 |
|
Uziel posted:Both are List<int>.
|
# ¿ Sep 22, 2016 20:04 |
|
Uziel posted:Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.
|
# ¿ Sep 22, 2016 20:11 |
|
NihilCredo posted:This is perhaps my favourite. VB.Net has an interesting legacy keyword called 'Static'. It has nothing to do with C-like static entities (those are called "Shared"). Rather, it can be used to declare a local variable in place of the usual Dim. If you do, the value of the variable is retained between each call of the function where the static variable appears.
|
# ¿ Nov 12, 2016 04:38 |
|
Jewel posted:to be fair, winxp also has a huge user base. doesn't mean you shouldn't wane it out and try to persuade to change the standard
|
# ¿ Mar 26, 2017 13:56 |
|
Ugh I've been trying to use f# on linux but it's such a disaster. VSCode works great as an editor but I randomly just can't get its breakpoints to work with mono so I can't debug. I thought I would try to see if .net core would work instead, but of course f# is completely broken in .net Core 2.0 Preview. I guess I could either try to use something else for mono debugging if there's anything else that supports f#, or I could try to install an older version of dotnet core, but I'm not totally sure if the released version of ionide even actually suppports debugging on dotnet core. It seems like other people have had the breakpoint issue but there just aren't enough people using f# with VSCode to care or something. Unfortunately it seems like dotnet core has actually made the f# situation more unstable on linux too, because probably all the effort is going to be focused on that from now on. I just hope .net core gets somewhat stabilized soon, but I'll probably have given up on f# again by then. mystes fucked around with this message at 15:16 on May 18, 2017 |
# ¿ May 18, 2017 15:11 |
|
quote:Use Windows and deploy on Linux? I know, sucky solution but at least on Windows the debugger works great. Now I'm trying to use .net core 1.0, and I haven't even gotten to the point of seeing if I can debug with it because I'm having a type issue that I didn't have with mono. I have a line that's like code:
mystes fucked around with this message at 15:49 on May 18, 2017 |
# ¿ May 18, 2017 15:47 |
|
Mr Shiny Pants posted:It is complaining about the output of the function? Use ignore on both cases? However it turns out I misunderstood the problem. I don't know if it's a problem in this version of the fsharp compiler or dotnet core itself, but the actual problem is that it doesn't like StreamReader(string) for some reason, and it's determined to call StreamReader(stream) (one of the other constructors). Looking at the .net standard reference at https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader?view=netstandard-1.6 the table of constructors at the bottom doesn't even have StreamReader(string) which makes me wonder if .net core therefore doesn't? And yet the example on that very page actually gives an example of using StreamReader(string)! code:
Edit: Oh god it appears to be true: http://stackoverflow.com/questions/37785384/new-streamreader-class-doesnt-accept-filename Why, Microsoft, why? Edit 2: OK, I changed it to System.IO.File.OpenText and it builds with dotnet core 1.0, and I can debug it in VSCode. However, since the auto-completion and error highlighting are I think still based on mono this is probably going to lead to its own headaches if it doesn't match the actual compiler. Drastic Actions posted:What do you mean? That .NET Core is going to get more focus than Mono? I can tell you that's not that case. I'm sure it's an issue with ionide rather than mono, but I might try seeing if upgrading mono helps. mystes fucked around with this message at 16:37 on May 18, 2017 |
# ¿ May 18, 2017 16:11 |
|
Oh never mind, I'm dumb. The breakpoint wasn't working because it was just using a version of the file I had compiled manually without debug information, so I'm back to mono and it's working fine now. I still apparently don't understand how to configure builds in VSCode at all, though. Luckily that means I can postpone learning anything about .net core.
|
# ¿ May 18, 2017 20:34 |
|
ljw1004 posted:I know you were asking about memory leaks with lambdas, but (1) you should be using async-await rather than lambda callbacks, (2) you should be cancelling the web request if its result is no longer needed, (3) what is this HTTPRequest/HTTPResponse class anyway? It looks like it's not System.Web.HttpRequest (which has different capitalization and lacks a Callback property) and I can't find it on Google, so I don't know how to write the code I think you should be writing instead. Why aren't you using "HttpClient' ?
|
# ¿ May 20, 2017 22:02 |
|
Is there some way to use the NEST c# elasticsearch API without tons of crazy lambda expressions? I'm talking about stuff like:code:
Actually, in general the API seems way crazier/dumber than the python one. There are also like 5 different ways to specify property mappings for objects, and for some reason the documentation doesn't seem to like to discuss the only one that seems to be even remotely readable (using attributes). Edit: Oh never mind. It does seem like an alternative does exist, although there don't seem to be as many examples for it. Argh, it looks like if you use that syntax you just end up entering stuff as strings without type safety, though. mystes fucked around with this message at 01:11 on Jun 26, 2017 |
# ¿ Jun 26, 2017 00:52 |
|
.NET Core 2.0 Preview 2 has been released, and f# appears to be working again for the moment.
|
# ¿ Jun 29, 2017 02:54 |
|
Xeom posted:New to this guys and I'm having an issue. I'm just trying to go through an array of strings in order to check if the word in the string is also in "enable1.txt". The while loop keeps advancing in the file until the end, and you don't do anything to reset the position to the beginning. This means that after the first time you go through the while loop, it will already be at the end. To make this code work, you would need to either open the file again in each iteration of the for loop (really terrible) or seek to the beginning each time (less terrible). The first code that B-Nasty gave is more efficient and solves this issue by switching the order of the loops, so that the outer loop reads through the file and you only have to do this a single time. quote:The lambda expression is the really confusing part. It seems to say "look for x, but hey x itself is a search function". Does the lambda function just tell Contains() give me everything you can find and put it into a list? x => input.Contains(x) is just like code:
mystes fucked around with this message at 03:46 on Jul 9, 2017 |
# ¿ Jul 9, 2017 03:41 |
|
Probably direct2d or something.
|
# ¿ Aug 6, 2017 01:05 |
|
Mr Shiny Pants posted:This is probably very simple, but my Google Fu is failing me and I can't seem to make it work so maybe you guys know: I'm not sure if "uuid" is supposed to a string or an object or whatever, but if it's supposed to be a string: code:
mystes fucked around with this message at 23:59 on Aug 6, 2017 |
# ¿ Aug 6, 2017 23:56 |
|
LongSack posted:Is there a way in visual studio to have classes automatically created when I start a new solution? Like when I start a new WPF project, I know that I am going to want
|
# ¿ Sep 14, 2017 03:47 |
|
Completely Ignoring the whole first paragraph and the WPF part, it sounds sort of like maybe LongSack just wants to create his own ORM essentially where he can create a class that corresponds to a database row and then use reflection or code generation for the actual database code based on the fields in the class?
|
# ¿ Sep 29, 2017 04:24 |
|
Gul Banana posted:https://twitter.com/joebelfiore/status/917071399541391360 rip mystes fucked around with this message at 13:55 on Oct 9, 2017 |
# ¿ Oct 9, 2017 13:41 |
|
LongSack posted:Also, can someone help me avoid the “unsigned application” thing with my installers? I have nearly a dozen tools that I have made available to my coworkers, and every time they run the installer, they have to go through the “install anyway” thing. I’d love to get rid of that warning. This page tells me what I need to do, but doesn’t really tell me how to do it. Edit to expand slightly: You need a code a code signing certificate. If you don't have an internal certificate authority set up as part of your windows domain, you will have to buy one (like buying an SSL certficate), but an internal certificate authority is probably actually the correct solution. Unfortunately, your company probably either won't have one or won't create a code signing certificate for you. Actually you might also just be able to generate your own self-signed code signing certificate and get your coworkers to add it to the windows certificate store, but even if windows allows that, I don't know if that would be better than having them click through the warnings. mystes fucked around with this message at 03:40 on Nov 1, 2017 |
# ¿ Nov 1, 2017 03:32 |
|
LongSack posted:I have an SSL cert from let’s encrypt for my website. Can I leverage that or is this something completely different? $20 is no big deal. $20 a year is no big deal. $200 is eh. $200 a year is a non starter. Actually it looks like I misremembered and the cheapest ones are more like $70, unfortunately.
|
# ¿ Nov 1, 2017 04:53 |
|
B-Nasty posted:We need a LetsEncrypt for CSCs.
|
# ¿ Nov 2, 2017 13:48 |
|
B-Nasty posted:They aren't, though. EV certs give you SmartScreen bonus points, but aren't required for desktop apps. quote:As far as locking a CSC to a website...at least that would help to prevent download hosting sites from injecting malware into installers or even compromised servers from the company. Though, that didn't help CCleaner. mystes fucked around with this message at 01:11 on Nov 3, 2017 |
# ¿ Nov 3, 2017 01:08 |
|
B-Nasty posted:I would argue that it's still better to have a CSC. Ideally, FooBarCorp would sign its binaries/installers on a reasonably secure development machine/CI server, where their marketing/download site might be running on some insecure shared host or using outdated Wordpress. When I download FooBar-Paint-Installer.exe and see that it is signed by foobarcorp.com, I have a slightly higher confidence than just the fact that my download was served by a server identified as foobarcorp.com.
|
# ¿ Nov 3, 2017 17:08 |
|
B-Nasty posted:Certs can be revoked when the hack is discovered, and with modern Windows versions, UAC will give you an ugly, un-skippable error message if you try to run an elevated, revoked exe. Also you could use certificate authority auth in your DNS to prevent new certs from being issued after you've obtained your CSC. mystes fucked around with this message at 18:55 on Nov 3, 2017 |
# ¿ Nov 3, 2017 18:52 |
|
fankey posted:Given a list of IP addresses, I'm using the following to determine the first address to response with a valid HTTP response
|
# ¿ Nov 18, 2017 01:29 |
|
I have a powershell script that calls some C# based on this using a nativewindow to create a global hotkey because that was the first thing I found a while ago, but it was inconvenient because then it's in the event loop and ties up the powershell interpreter, so I changed it to run in a separate thread. However, now I have the problem that I don't have a way to signal the thread to shut down (there's no Form so I can't use Invoke). Since the code already has to override WndProc should I just use PostMessage or something? I guess I could use SetTimer from user32.dll to set a timer and then check a variable periodically to see if the thread should shut down, but this would just add an extra step I think? Maybe there's a better way to do this, but I know absolutely nothing about the low level win32 api. I'm not sure if there's a higher level way to get at the event loop in this situation?
|
# ¿ Dec 7, 2017 02:57 |
|
|
# ¿ May 3, 2024 14:42 |
|
Bind a global hotkey without creating a visible window, in an object that I can manipulate from powershell for autohotkey type functionality. This is working, I just don't have a way to signal the thread running that to shut down, which means that the process won't actually terminate when I close the powershell interpreter. All of the examples I can find for this sort of situation use Control.Invoke, but I don't have any winforms controls, so I don't know if there's some other way to queue some sort of action from the other thread? The background of what I'm trying to do: The idea is that I will be able to instantiate my class from powershell and register various hotkeys. Before I changed it to be multithreaded I was passing powershell functions as delegates that were then called by the C# code, but currently I am now using a ConcurrentQueue which the thread with the nativewindow object uses to signal that the hotkey have been pressed, which is working fine, but I just don't know how to signal the thread to shut down. I could also switch to using a keyboad hook but I don't know if this would make any difference? Basically, does just using Application.Run without an actual winforms window create some sort of message queue that I can access directly? I tried searching, but as I said, the only thing I can find is Control.Invoke which normally handles this automatically. It seems like there should be a more direct way to do whatever Control.Invoke does myself, but I can't figure it out. Since I have no idea how Control.Invoke works, it's also possible that it literally just sends a message to the window and there's handler code in winforms for this that won't exist in this case because it's not a winforms window, but I have no idea. I may be fundamentally misunderstanding how this stuff works, but I find it a bit annoying that I can't find any actual explanation. mystes fucked around with this message at 04:56 on Dec 7, 2017 |
# ¿ Dec 7, 2017 04:32 |