2007-01-08 00:03:05 +01:00
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
2009-07-29 07:43:02 +02:00
// Aegisub Project http://www.aegisub.org/
/// @file dialog_version_check.cpp
/// @brief Version Checker dialogue box and logic
/// @ingroup configuration_ui
///
2007-01-08 00:03:05 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2012-06-21 04:09:40 +02:00
# ifdef WITH_UPDATE_CHECKER
2012-02-10 01:03:46 +01:00
# include "dialog_version_check.h"
2013-01-04 16:01:50 +01:00
# ifdef _MSC_VER
# pragma warning(disable : 4250) // 'boost::asio::basic_socket_iostream<Protocol>' : inherits 'std::basic_ostream<_Elem,_Traits>::std::basic_ostream<_Elem,_Traits>::_Add_vtordisp2' via dominance
# endif
# include "compat.h"
# include "options.h"
# include "string_codec.h"
# include "version.h"
# include <libaegisub/dispatch.h>
# include <libaegisub/exception.h>
# include <libaegisub/line_iterator.h>
# include <libaegisub/scoped_ptr.h>
2010-01-31 15:55:03 +01:00
# include <wx/button.h>
2012-02-10 01:03:46 +01:00
# include <wx/checkbox.h>
2010-01-31 15:55:03 +01:00
# include <wx/dialog.h>
2012-02-10 01:03:46 +01:00
# include <wx/event.h>
# include <wx/hyperlink.h>
# include <wx/intl.h>
# include <wx/platinfo.h>
2010-01-31 15:55:03 +01:00
# include <wx/sizer.h>
# include <wx/statline.h>
2012-02-10 01:03:46 +01:00
# include <wx/stattext.h>
# include <wx/string.h>
2010-01-31 15:55:03 +01:00
# include <wx/textctrl.h>
2012-02-10 01:03:46 +01:00
# include <algorithm>
2013-01-04 16:01:50 +01:00
# include <ctime>
# include <boost/algorithm/string/classification.hpp>
# include <boost/algorithm/string/split.hpp>
# include <boost/asio/ip/tcp.hpp>
# include <boost/format.hpp>
2012-09-25 01:35:27 +02:00
# include <functional>
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
# include <memory>
2010-06-05 22:16:30 +02:00
# include <set>
2010-01-31 15:55:03 +01:00
# include <vector>
2009-09-10 15:06:40 +02:00
2012-08-18 05:13:24 +02:00
# ifdef __APPLE__
# include <CoreFoundation/CoreFoundation.h>
# endif
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
// Allocate global lock mutex declared in header
2013-01-04 16:01:50 +01:00
std : : mutex VersionCheckLock ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
namespace {
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
struct AegisubUpdateDescription {
2013-01-04 16:01:50 +01:00
std : : string url ;
std : : string friendly_name ;
std : : string description ;
2013-11-21 18:13:36 +01:00
AegisubUpdateDescription ( std : : string url , std : : string friendly_name , std : : string description )
: url ( std : : move ( url ) ) , friendly_name ( std : : move ( friendly_name ) ) , description ( std : : move ( description ) ) { }
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
} ;
2013-01-04 16:01:50 +01:00
class VersionCheckerResultDialog : public wxDialog {
void OnCloseButton ( wxCommandEvent & evt ) ;
void OnRemindMeLater ( wxCommandEvent & evt ) ;
void OnClose ( wxCloseEvent & evt ) ;
wxCheckBox * automatic_check_checkbox ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
public :
2013-01-04 16:01:50 +01:00
VersionCheckerResultDialog ( wxString const & main_text , const std : : vector < AegisubUpdateDescription > & updates ) ;
2012-03-25 06:05:06 +02:00
2013-11-21 18:13:36 +01:00
bool ShouldPreventAppExit ( ) const override { return false ; }
2013-01-04 16:01:50 +01:00
} ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
VersionCheckerResultDialog : : VersionCheckerResultDialog ( wxString const & main_text , const std : : vector < AegisubUpdateDescription > & updates )
2013-11-21 18:13:36 +01:00
: wxDialog ( nullptr , - 1 , _ ( " Version Checker " ) )
2013-01-04 16:01:50 +01:00
{
const int controls_width = 500 ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
wxSizer * main_sizer = new wxBoxSizer ( wxVERTICAL ) ;
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
wxStaticText * text = new wxStaticText ( this , - 1 , main_text ) ;
text - > Wrap ( controls_width ) ;
main_sizer - > Add ( text , 0 , wxBOTTOM | wxEXPAND , 6 ) ;
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2013-01-04 16:01:50 +01:00
for ( auto const & update : updates ) {
main_sizer - > Add ( new wxStaticLine ( this ) , 0 , wxEXPAND | wxALL , 6 ) ;
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
text = new wxStaticText ( this , - 1 , to_wx ( update . friendly_name ) ) ;
wxFont boldfont = text - > GetFont ( ) ;
boldfont . SetWeight ( wxFONTWEIGHT_BOLD ) ;
text - > SetFont ( boldfont ) ;
main_sizer - > Add ( text , 0 , wxEXPAND | wxBOTTOM , 6 ) ;
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
wxTextCtrl * descbox = new wxTextCtrl ( this , - 1 , to_wx ( update . description ) , wxDefaultPosition , wxSize ( controls_width , 60 ) , wxTE_MULTILINE | wxTE_READONLY ) ;
main_sizer - > Add ( descbox , 0 , wxEXPAND | wxBOTTOM , 6 ) ;
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2013-01-04 16:01:50 +01:00
main_sizer - > Add ( new wxHyperlinkCtrl ( this , - 1 , to_wx ( update . url ) , to_wx ( update . url ) ) , 0 , wxALIGN_LEFT | wxBOTTOM , 6 ) ;
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
automatic_check_checkbox = new wxCheckBox ( this , - 1 , _ ( " &Auto Check for Updates " ) ) ;
automatic_check_checkbox - > SetValue ( OPT_GET ( " App/Auto/Check For Updates " ) - > GetBool ( ) ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-11-21 18:13:36 +01:00
wxButton * remind_later_button = nullptr ;
2013-01-04 16:01:50 +01:00
if ( updates . size ( ) > 0 )
remind_later_button = new wxButton ( this , wxID_NO , _ ( " Remind me again in a &week " ) ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
wxButton * close_button = new wxButton ( this , wxID_OK , _ ( " &Close " ) ) ;
SetAffirmativeId ( wxID_OK ) ;
SetEscapeId ( wxID_OK ) ;
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
if ( updates . size ( ) )
main_sizer - > Add ( new wxStaticLine ( this ) , 0 , wxEXPAND | wxALL , 6 ) ;
main_sizer - > Add ( automatic_check_checkbox , 0 , wxEXPAND | wxBOTTOM , 6 ) ;
2007-01-08 00:03:05 +01:00
2013-11-21 18:13:36 +01:00
auto button_sizer = new wxStdDialogButtonSizer ( ) ;
2013-01-04 16:01:50 +01:00
button_sizer - > AddButton ( close_button ) ;
if ( remind_later_button )
button_sizer - > AddButton ( remind_later_button ) ;
button_sizer - > Realize ( ) ;
main_sizer - > Add ( button_sizer , 0 , wxEXPAND , 0 ) ;
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
wxSizer * outer_sizer = new wxBoxSizer ( wxVERTICAL ) ;
outer_sizer - > Add ( main_sizer , 0 , wxALL | wxEXPAND , 12 ) ;
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2013-01-04 16:01:50 +01:00
SetSizerAndFit ( outer_sizer ) ;
Centre ( ) ;
Show ( ) ;
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2013-12-12 03:25:13 +01:00
Bind ( wxEVT_BUTTON , std : : bind ( & VersionCheckerResultDialog : : Close , this , false ) , wxID_OK ) ;
Bind ( wxEVT_BUTTON , & VersionCheckerResultDialog : : OnRemindMeLater , this , wxID_NO ) ;
2013-01-04 16:01:50 +01:00
Bind ( wxEVT_CLOSE_WINDOW , & VersionCheckerResultDialog : : OnClose , this ) ;
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
void VersionCheckerResultDialog : : OnRemindMeLater ( wxCommandEvent & ) {
// In one week
time_t new_next_check_time = time ( nullptr ) + 7 * 24 * 60 * 60 ;
OPT_SET ( " Version/Next Check " ) - > SetInt ( new_next_check_time ) ;
Close ( ) ;
2007-01-08 00:03:05 +01:00
}
2013-01-04 16:01:50 +01:00
void VersionCheckerResultDialog : : OnClose ( wxCloseEvent & ) {
OPT_SET ( " App/Auto/Check For Updates " ) - > SetBool ( automatic_check_checkbox - > GetValue ( ) ) ;
Destroy ( ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
}
2013-01-04 16:01:50 +01:00
DEFINE_SIMPLE_EXCEPTION_NOINNER ( VersionCheckError , agi : : Exception , " versioncheck " )
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
void PostErrorEvent ( bool interactive , wxString const & error_text ) {
if ( interactive ) {
agi : : dispatch : : Main ( ) . Async ( [ = ] {
2013-12-12 00:11:06 +01:00
new VersionCheckerResultDialog ( error_text , { } ) ;
2013-01-04 16:01:50 +01:00
} ) ;
}
}
static const char * GetOSShortName ( ) {
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
int osver_maj , osver_min ;
wxOperatingSystemId osid = wxGetOsVersion ( & osver_maj , & osver_min ) ;
2013-01-04 16:01:50 +01:00
if ( osid & wxOS_WINDOWS_NT ) {
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
if ( osver_maj = = 5 & & osver_min = = 0 )
2011-09-28 21:43:11 +02:00
return " win2k " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osver_maj = = 5 & & osver_min = = 1 )
2011-09-28 21:43:11 +02:00
return " winxp " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osver_maj = = 5 & & osver_min = = 2 )
2011-09-28 21:43:11 +02:00
return " win2k3 " ; // this is also xp64
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osver_maj = = 6 & & osver_min = = 0 )
2011-09-28 21:43:11 +02:00
return " win60 " ; // vista and server 2008
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osver_maj = = 6 & & osver_min = = 1 )
2011-09-28 21:43:11 +02:00
return " win61 " ; // 7 and server 2008r2
2012-02-10 01:03:46 +01:00
else if ( osver_maj = = 6 & & osver_min = = 2 )
return " win62 " ; // 8
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else
2011-09-28 21:43:11 +02:00
return " windows " ; // future proofing? I doubt we run on nt4
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
}
2012-08-18 05:13:28 +02:00
// CF returns 0x10 for some reason, which wx has recently started
// turning into 10
2013-01-04 16:01:50 +01:00
else if ( osid & wxOS_MAC_OSX_DARWIN & & ( osver_maj = = 0x10 | | osver_maj = = 10 ) ) {
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
// ugliest hack in the world? nah.
2011-09-28 21:43:11 +02:00
static char osxstring [ ] = " osx00 " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
char minor = osver_min > > 4 ;
char patch = osver_min & 0x0F ;
osxstring [ 3 ] = minor + ( ( minor < = 9 ) ? ' 0 ' : ( ' a ' - 1 ) ) ;
osxstring [ 4 ] = patch + ( ( patch < = 9 ) ? ' 0 ' : ( ' a ' - 1 ) ) ;
return osxstring ;
2007-01-08 00:03:05 +01:00
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_LINUX )
2011-09-28 21:43:11 +02:00
return " linux " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_FREEBSD )
2011-09-28 21:43:11 +02:00
return " freebsd " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_OPENBSD )
2011-09-28 21:43:11 +02:00
return " openbsd " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_NETBSD )
2011-09-28 21:43:11 +02:00
return " netbsd " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_SOLARIS )
2011-09-28 21:43:11 +02:00
return " solaris " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_AIX )
2011-09-28 21:43:11 +02:00
return " aix " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX_HPUX )
2011-09-28 21:43:11 +02:00
return " hpux " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_UNIX )
2011-09-28 21:43:11 +02:00
return " unix " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_OS2 )
2011-09-28 21:43:11 +02:00
return " os2 " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else if ( osid & wxOS_DOS )
2011-09-28 21:43:11 +02:00
return " dos " ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
else
2011-09-28 21:43:11 +02:00
return " unknown " ;
2007-01-08 00:03:05 +01:00
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
# ifdef WIN32
typedef BOOL ( WINAPI * PGetUserPreferredUILanguages ) ( DWORD dwFlags , PULONG pulNumLanguages , wchar_t * pwszLanguagesBuffer , PULONG pcchLanguagesBuffer ) ;
2012-02-10 01:03:46 +01:00
// Try using Win 6+ functions if available
2013-01-04 16:01:50 +01:00
static wxString GetUILanguage ( ) {
2012-02-20 19:22:12 +01:00
agi : : scoped_holder < HMODULE , BOOL ( __stdcall * ) ( HMODULE ) > kernel32 ( LoadLibraryW ( L " kernel32.dll " ) , FreeLibrary ) ;
if ( ! kernel32 ) return " " ;
2012-02-10 01:03:46 +01:00
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
PGetUserPreferredUILanguages gupuil = ( PGetUserPreferredUILanguages ) GetProcAddress ( kernel32 , " GetUserPreferredUILanguages " ) ;
2012-02-20 19:22:12 +01:00
if ( ! gupuil ) return " " ;
2012-02-10 01:03:46 +01:00
ULONG numlang = 0 , output_len = 0 ;
2012-02-20 19:22:12 +01:00
if ( gupuil ( MUI_LANGUAGE_NAME , & numlang , 0 , & output_len ) ! = TRUE | | ! output_len )
return " " ;
std : : vector < wchar_t > output ( output_len ) ;
if ( ! gupuil ( MUI_LANGUAGE_NAME , & numlang , & output [ 0 ] , & output_len ) | | numlang < 1 )
return " " ;
2012-02-10 01:03:46 +01:00
2012-02-20 19:22:12 +01:00
// We got at least one language, just treat it as the only, and a null-terminated string
return & output [ 0 ] ;
2012-02-10 01:03:46 +01:00
}
2013-01-04 16:01:50 +01:00
static wxString GetSystemLanguage ( ) {
2012-02-10 01:03:46 +01:00
wxString res = GetUILanguage ( ) ;
if ( ! res )
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
// On an old version of Windows, let's just return the LANGID as a string
2012-02-10 01:03:46 +01:00
res = wxString : : Format ( " x-win%04x " , GetUserDefaultUILanguage ( ) ) ;
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
return res ;
}
2012-08-18 05:13:24 +02:00
# elif __APPLE__
2013-01-04 16:01:50 +01:00
static wxString GetSystemLanguage ( ) {
2012-08-18 05:13:24 +02:00
CFLocaleRef locale = CFLocaleCopyCurrent ( ) ;
CFStringRef localeName = ( CFStringRef ) CFLocaleGetValue ( locale , kCFLocaleIdentifier ) ;
2012-08-18 05:13:28 +02:00
char buf [ 128 ] = { 0 } ;
2012-08-18 05:13:24 +02:00
CFStringGetCString ( localeName , buf , sizeof buf , kCFStringEncodingUTF8 ) ;
CFRelease ( locale ) ;
return wxString : : FromUTF8 ( buf ) ;
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
# else
2013-01-04 16:01:50 +01:00
static wxString GetSystemLanguage ( ) {
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
return wxLocale : : GetLanguageInfo ( wxLocale : : GetSystemLanguage ( ) ) - > CanonicalName ;
2007-01-08 00:03:05 +01:00
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
# endif
2013-01-04 16:01:50 +01:00
static wxString GetAegisubLanguage ( ) {
2012-12-23 00:18:38 +01:00
return to_wx ( OPT_GET ( " App/Language " ) - > GetString ( ) ) ;
2012-09-24 22:00:41 +02:00
}
2013-01-04 16:01:50 +01:00
void DoCheck ( bool interactive ) {
boost : : asio : : ip : : tcp : : iostream stream ;
stream . connect ( UPDATE_CHECKER_SERVER , " http " ) ;
if ( ! stream )
2012-12-23 00:18:38 +01:00
throw VersionCheckError ( from_wx ( _ ( " Could not connect to updates server. " ) ) ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
stream < < boost : : format (
2013-02-17 04:47:31 +01:00
" GET %s?rev=%d&rel=%d&os=%s&lang=%s&aegilang=%s HTTP/1.0 \r \n "
2013-01-04 16:01:50 +01:00
" User-Agent: Aegisub %s \r \n "
" Host: %s \r \n "
" Accept: */* \r \n "
" Connection: close \r \n \r \n " )
% UPDATE_CHECKER_BASE_URL
% GetSVNRevision ( )
% ( GetIsOfficialRelease ( ) ? 1 : 0 )
% GetOSShortName ( )
% GetSystemLanguage ( )
% GetAegisubLanguage ( )
% GetAegisubLongVersionString ( )
% UPDATE_CHECKER_SERVER
;
std : : string http_version ;
stream > > http_version ;
int status_code ;
stream > > status_code ;
if ( ! stream | | http_version . substr ( 0 , 5 ) ! = " HTTP/ " )
2012-12-23 00:18:38 +01:00
throw VersionCheckError ( from_wx ( _ ( " Could not download from updates server. " ) ) ) ;
2013-01-04 16:01:50 +01:00
if ( status_code ! = 200 )
throw VersionCheckError ( from_wx ( wxString : : Format ( _ ( " HTTP request failed, got HTTP response %d. " ) , status_code ) ) ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
stream . ignore ( std : : numeric_limits < std : : streamsize > : : max ( ) , ' \n ' ) ;
// Skip the headers since we don't care about them
for ( auto const & header : agi : : line_iterator < std : : string > ( stream ) )
if ( header . empty ( ) ) break ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
std : : vector < AegisubUpdateDescription > results ;
for ( auto const & line : agi : : line_iterator < std : : string > ( stream ) ) {
if ( line . empty ( ) ) continue ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
std : : vector < std : : string > parsed ;
boost : : split ( parsed , line , boost : : is_any_of ( " | " ) ) ;
2012-02-10 01:03:46 +01:00
if ( parsed . size ( ) ! = 6 ) continue ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
// 0 and 2 being things that never got used
std : : string revision = parsed [ 1 ] ;
std : : string url = inline_string_decode ( parsed [ 3 ] ) ;
std : : string friendlyname = inline_string_decode ( parsed [ 4 ] ) ;
std : : string description = inline_string_decode ( parsed [ 5 ] ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
if ( atoi ( revision . c_str ( ) ) < = GetSVNRevision ( ) )
2007-01-08 00:03:05 +01:00
continue ;
2013-01-04 16:01:50 +01:00
results . emplace_back ( url , friendlyname , description ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
}
2007-01-08 00:03:05 +01:00
2013-01-04 16:01:50 +01:00
if ( ! results . empty ( ) | | interactive ) {
agi : : dispatch : : Main ( ) . Async ( [ = ] {
wxString text ;
if ( results . size ( ) = = 1 )
text = _ ( " An update to Aegisub was found. " ) ;
else if ( results . size ( ) > 1 )
text = _ ( " Several possible updates to Aegisub were found. " ) ;
else
text = _ ( " There are no updates to Aegisub. " ) ;
new VersionCheckerResultDialog ( text , results ) ;
} ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
}
}
}
2013-01-04 16:01:50 +01:00
void PerformVersionCheck ( bool interactive ) {
agi : : dispatch : : Background ( ) . Async ( [ = ] {
if ( ! interactive ) {
// Automatic checking enabled?
if ( ! OPT_GET ( " App/Auto/Check For Updates " ) - > GetBool ( ) )
return ;
// Is it actually time for a check?
time_t next_check = OPT_GET ( " Version/Next Check " ) - > GetInt ( ) ;
if ( next_check > time ( nullptr ) )
return ;
}
2009-07-29 07:43:02 +02:00
2013-01-04 16:01:50 +01:00
if ( ! VersionCheckLock . try_lock ( ) ) return ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
try {
DoCheck ( interactive ) ;
2012-02-10 01:03:46 +01:00
}
2013-01-04 16:01:50 +01:00
catch ( const agi : : Exception & e ) {
PostErrorEvent ( interactive , wxString : : Format (
_ ( " There was an error checking for updates to Aegisub: \n %s \n \n If other applications can access the Internet fine, this is probably a temporary server problem on our end. " ) ,
e . GetMessage ( ) ) ) ;
2012-02-10 01:03:46 +01:00
}
2013-01-04 16:01:50 +01:00
catch ( . . . ) {
PostErrorEvent ( interactive , _ ( " An unknown error occurred while checking for updates to Aegisub. " ) ) ;
2012-02-10 01:03:46 +01:00
}
2013-01-04 16:01:50 +01:00
VersionCheckLock . unlock ( ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
2013-01-04 16:01:50 +01:00
agi : : dispatch : : Main ( ) . Async ( [ ] {
time_t new_next_check_time = time ( nullptr ) + 60 * 60 ; // in one hour
OPT_SET ( " Version/Next Check " ) - > SetInt ( new_next_check_time ) ;
} ) ;
} ) ;
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
}
2012-06-21 04:09:40 +02:00
# endif