![]() |
|
[.NET] [RELEASE][UPDATED] AutoUpdate class [READY TO USE ][NO FILE GENERATED!] - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] [RELEASE][UPDATED] AutoUpdate class [READY TO USE ][NO FILE GENERATED!] (/showthread.php?tid=4753321) Pages: Pages
1
2
|
[RELEASE][UPDATED] AutoUpdate class [READY TO USE ][NO FILE GENERATED!] - Gr0wlit - Mar 29, 2015 UPDATED: Now it doesn't generate any file. I've applied He B TeMy and Only3 suggestions. Hi all, one of the most important feature that your application can have is the AutoUpdate feature: each application, even if developed by the most experienced coder, can have bugs; it is developer's work trying to build the more "bugs free" software to release to his costumers. Since I don't see a lot fo thread about it, I'm currently releasing a perfectible ready to use class that will help you to implement the AutoUpdate feature to your products. WHAT YOU NEED:
HOW IT WORKS: Basically, the idea is simple (and I'm sure already used by someone): since creating 2 different exe (main application and updater) is a TERRIBLE idea in my opinion, we will work with cmd commands; first, the class will check the most updated version, if there is a new version, will download the updated software in the Temp folder (all asynchronously to avoid UI freezing). Then it will generate some CMD instructions that will (in order):
All this will be launched in HIDDEN mode, the fnial user will not see anything (as you can see in the .gif); before running these instructions, it will close your application (otherwise the update process will not work). As a result, you will have your updated application opened, without any other file! ANIMATED GIF: Spoiler (Click to View) HOW TO USE IT: Just import the class into your project, to call it you just need to instanciate the class and pass 3 parameters:
Pretty cool things that I liked to add: my autoupdate class provide 3 events that you can call from your application:
First: declare the class: PHP Code then, when you want to check if there are updates (for example in a button): PHP Code Finish! My autoupdate class will do the rest. To call the event provided by the class: PHP Code DOWNLOAD https://mega.co.nz/#!I4E2CaAD!mmIXJ7ojNf-OECsxJlFnZizUbW8M4XyLMnKy0FG47XM * - He B TeMy - Mar 29, 2015 You talk about not using an Updater because that's a bad idea, but you're fine with writting a bat file to the disk and running it? Code .AppendLine("TASKKILL /F /IM " & _CurrentPath.FileName)Using this to kill your program inside the .bat? lol, what if another program has the same name of yours? Code AppendLine("del """ & _CurrentPath.Path & _CurrentPath.FileName & """")Can you read what the commands do please? Why are you using /-y parameter ? You know what happens if the file exists with that parameter? Code .AppendLine("sleep 2")Does this even work? Code .AppendLine("call :deleteSelf&exit /b")Wtf is this for? What does the last line do? .CreateNoWindow = True * - Gr0wlit - Mar 29, 2015 That is why I wrote the "Things to consider" section. Anyway, let me answer your questions. (Mar 29, 2015 03:24 PM)He B TeMy Wrote: You talk about not using an Updater because that's a bad idea, but you're fine with writting a bat file to the disk and running it? Uhmm yes? What's the problem? A batch file is more elegant that a separated exe that do the job. I don't see the problem. Quote: Basically the only way to delete an .exe from a batch script that I know is what I wrote (Things to consider section). Quote: Yes, why it is a bad idea? Quote: My fault, I was trying different ways and I forgot to delete that line. Quote: That line call a subroutine immediately below that will delete the script itself. I used to call a subroutine to avoid problems. * - evilivid - Mar 29, 2015 LOL this is so clever, I might use this. Yeah it works, the thread is 10/10 good work OP. * - He B TeMy - Mar 29, 2015 (Mar 29, 2015 03:44 PM)Gr0wlit Wrote: Uhmm yes? What's the problem? A batch file is more elegant that a separated exe that do the job. I don't see the problem. Is more elegant? Because it's smaller? How about you run it directly on cmd without writing to disk? (Mar 29, 2015 03:44 PM)Gr0wlit Wrote: Basically the only way to delete an .exe from a batch script that I know is what I wrote (Things to consider section). How about you close the application gracefully just after you launch the script? And perhaps do a little pause on the script to let the application close first. (Mar 29, 2015 03:44 PM)Gr0wlit Wrote: Yes, why it is a bad idea? No you don't, otherwise you'd know the bad idea, there's no point in supplying that parameter because it's the default, you probably know now but i tell you anyway, that forces every overwrite action to prompt the user, i know you do a "delete" before, but if for some reason that doesn't work, you're stuck with prompting the user something which will possibly break the application. ... And, since i forgot to finish that last line above... you can remove your .CreateNoWindow = true, it does nothing on your code. Edit: Yes. Code Private _CurrentPath As CurrentPathWhat is this for? Ever heard of Code Application.ExecutablePath* - Hawk HF - Mar 29, 2015 This is a nice thread and is a much greater contribution than many members have given. While there may be a few areas that could be improved upon, I appreciate the time you have taken to contribute to the .NET section. Nice release. * - nuk - Mar 29, 2015 I agree with Hawk... this is very useful and is going to help a lot of members out ;) Thanks for sharing this OP! ;) * - Gr0wlit - Mar 29, 2015 (Mar 29, 2015 05:42 PM)He B TeMy Wrote: Is more elegant? Because it's smaller? No, because is a smart and clean way to do that operation. Run directly from CMD can be a great idea, I will give a try Quote:How about you close the application gracefully just after you launch the script? And perhaps do a little pause on the script to let the application close first. I wanted to do an indipendent class, without this kind of interaction with the main app. Quote:No you don't, otherwise you'd know the bad idea, there's no point in supplying that parameter because it's the default, you probably know now but i tell you anyway, that forces every overwrite action to prompt the user, i know you do a "delete" before, but if for some reason that doesn't work, you're stuck with prompting the user something which will possibly break the application. Didn't think that could break the application, that's why I've used it. I will try Quote: Are you able to read the whole code? You will see that I use it to valorize some other parts of code, in order to avoid to write a code full of GetDirectoryName ecc, that make more confusion. Yes I've heard of it ( as you can read is a parameter that you pass at class initialization). Anyway, other parts of code that you want to criticize? Maybe some name of variables? * - Only3 - Mar 30, 2015 u dont need bat file https://hackforums.net/showthread.php?tid=1341791 * - Gr0wlit - Mar 30, 2015 I've UPDATED the class. Now it doesn't generate any file, it will run an hidden cmd window that do the trick. Important thing to consider is that the class will try to close your application, and after 2 seconds it will run the code.. The application must be closed in order to update. * - He B TeMy - Mar 30, 2015 You should give atleast 10s for it to close tho... I appreciate you taking feedback, just one more thing as i told you, you can remove Code .Append("del """ & _CurrentPath.Path & _CurrentPath.FileName & """ && ")* - Gr0wlit - Mar 30, 2015 (Mar 30, 2015 02:41 PM)He B TeMy Wrote: You should give atleast 10s for it to close tho... I don't know, 10s can be to much for a kind of application and not enough for other.. Maybe I will put is as a parameter.. Quote:I appreciate you taking feedback, just one more thing as i told you, you can remove Yes, it can be useless but I haven't deleted it just because in this manner I have one more confirm that the file is removed.. * - TazzyOpz - Mar 30, 2015 (Mar 30, 2015 03:15 AM)Only3 Wrote: u dont need bat file https://hackforums.net/showthread.php?tid=1341791 This is a much better method. I've also used that it in the past. (Mar 30, 2015 02:22 PM)Gr0wlit Wrote: I've UPDATED the class. Now it doesn't generate any file, it will run an hidden cmd window that do the trick. Indeed. You could always force close your application though as well to ensure the process is no longer running. Just Kill the process via it's Directory. However I'd only do that if you're running into issues where your program stays running in memory. * - He B TeMy - Mar 30, 2015 (Mar 30, 2015 02:54 PM)Gr0wlit Wrote: Yes, it can be useless but I haven't deleted it just because in this manner I have one more confirm that the file is removed.. That doesn't make sense man... "one more confirm"? If the first fails, the move will fail too, because it can't overwrite if something bad happens anyway. But hey, i'm just sayin'. And the 10s stuff i'd put it because of a generalization, i know some apps need 1s, others may need more, but Application.Exit() should terminate it in 10seconds (*should*). But that must be adjusted anyway if people do you use your class, they'll know better. (i hope) (Mar 30, 2015 02:57 PM)TazzyOpz Wrote: Indeed. You could always force close your application though as well to ensure the process is no longer running. Just Kill the process via it's Directory. However I'd only do that if you're running into issues where your program stays running in memory. You should never kill a process like that. Don't suggest a kill method on a Release of a class for public usage, it's just bad. Whoever uses this class should know how many seconds to wait in the batch file if they don't really want to use a separate application to update... if they fail the calculations, that's their fault, but don't just kill an app. * - TazzyOpz - Mar 30, 2015 (Mar 30, 2015 03:07 PM)He B TeMy Wrote: You should never kill a process like that. Quote:"However I'd only do that if you're running into issues where your program stays running in memory" I'm not saying you should do that I'm say you could do that as an options if a task is still running in the program while you want to update. I know it' not the best. I'm just saying it can be done that way if needed. |