@@ -707,105 +707,107 @@ int main(int argc, char* argv[])
707
707
708
708
import_file_path = fs_import_file_path.string ();
709
709
710
+ #if !defined(__ANDROID__)
711
+ if (command_line::has_arg (vm, arg_ipfs_import))
712
+ {
713
+ std::atomic<bool > downloadInProgress (true );
714
+
715
+ boost::filesystem::path export_path = boost::filesystem::path (m_config_folder) / " export" ;
716
+ if (!boost::filesystem::exists (export_path))
717
+ {
718
+ boost::filesystem::create_directories (export_path);
719
+ }
710
720
711
- if (command_line::has_arg (vm, arg_ipfs_import))
712
- {
713
- std::atomic<bool > downloadInProgress (true );
714
-
715
- boost::filesystem::path export_path = boost::filesystem::path (m_config_folder) / " export" ;
716
- if (!boost::filesystem::exists (export_path))
717
- {
718
- boost::filesystem::create_directories (export_path);
719
- }
720
-
721
- opt_verify = false ;
722
- boost::filesystem::path ipfs_path = boost::filesystem::path (m_config_folder) / " ipfs" ;
723
- std::string ipfs_path_str = ipfs_path.string ();
724
- std::string startResult = Start (const_cast <char *>(ipfs_path_str.c_str ()), ipfs_port);
725
-
726
- rapidjson::Document doc;
727
- if (doc.Parse (startResult.c_str ()).HasParseError ()) {
728
- MGINFO (" IPFS start response parse error" );
729
- return 0 ;
730
- }
731
-
732
- bool fail = false ;
733
-
734
- if (doc.HasMember (" Status" ) && doc[" Status" ].IsString () &&
735
- std::string (doc[" Status" ].GetString ()) == " success" &&
736
- doc.HasMember (" Data" ) && doc[" Data" ].IsObject ()) {
737
- const rapidjson::Value& dataVal = doc[" Data" ];
738
- if (dataVal.IsObject ()) {
739
- const auto & data = dataVal.GetObject ();
740
- if (data.HasMember (" peerId" ) && data[" peerId" ].IsString ()) {
741
- MGINFO (" IPFS Started with Peer ID: " << data[" peerId" ].GetString ());
742
-
743
- if (boost::filesystem::exists (import_file_path)) {
744
- boost::filesystem::remove (import_file_path);
745
- }
746
-
747
- std::thread progressThread ([&]() {
748
- using boost::posix_time::ptime;
749
- using boost::posix_time::microsec_clock;
750
- using boost::posix_time::time_duration;
751
- using boost::posix_time::to_tm;
752
-
753
- while (downloadInProgress) {
754
- if (boost::filesystem::exists (import_file_path)) {
755
- std::uintmax_t size = boost::filesystem::file_size (import_file_path);
756
-
757
- ptime now = microsec_clock::local_time ();
758
- time_duration td = now.time_of_day ();
759
- struct tm tm_now = to_tm (now);
760
-
761
- std::ostringstream time_ss;
762
- time_ss << std::put_time (&tm_now, " %Y-%m-%d %H:%M:%S" )
763
- << ' .' << std::setw (3 ) << std::setfill (' 0' ) << td.total_milliseconds () % 1000 ;
764
-
765
- std::ostringstream oss;
766
- oss << time_ss.str () << " I Downloaded: " << (size / (1024 * 1024 )) << " MB" ;
767
-
768
- std::cout << " \r " << oss.str () << std::flush;
769
- }
770
-
771
- std::this_thread::sleep_for (std::chrono::seconds (1 ));
772
- }
773
- });
774
-
775
- MGINFO (" Downloading blockchain from IPFS, this might take a few minutes.." );
776
-
777
- const std::string getCid = " /ipns/blockchain.raw.scala.network" ;
778
- std::string downloadResult = Get ((char *)getCid.c_str (), (char *)import_file_path.c_str (), true );
779
- downloadInProgress = false ;
780
- progressThread.join ();
721
+ opt_verify = false ;
722
+ boost::filesystem::path ipfs_path = boost::filesystem::path (m_config_folder) / " ipfs" ;
723
+ std::string ipfs_path_str = ipfs_path.string ();
724
+ std::string startResult = Start (const_cast <char *>(ipfs_path_str.c_str ()), ipfs_port);
781
725
782
- rapidjson::Document dlDoc ;
783
- if (dlDoc .Parse (downloadResult .c_str ()).HasParseError ()) {
784
- MGINFO (" Download result parse error" );
785
- return 0 ;
786
- }
726
+ rapidjson::Document doc ;
727
+ if (doc .Parse (startResult .c_str ()).HasParseError ()) {
728
+ MGINFO (" IPFS start response parse error" );
729
+ return 0 ;
730
+ }
787
731
788
- if (dlDoc.HasMember (" Status" ) && dlDoc[" Status" ].IsString () &&
789
- std::string (dlDoc[" Status" ].GetString ()) == " success" ) {
790
- MGINFO (" Blockchain downloaded from IPFS" );
791
- } else {
792
- MGINFO (" Blockchain download failed" );
793
- }
732
+ bool fail = false ;
794
733
795
- } else {
796
- fail = true ;
797
- }
798
- }
799
- } else {
800
- fail = true ;
801
- }
802
-
803
- if (fail) {
804
- MGINFO (" IPFS failed to initialize, exiting!" );
805
- return 0 ;
806
- }
807
- }
734
+ if (doc.HasMember (" Status" ) && doc[" Status" ].IsString () &&
735
+ std::string (doc[" Status" ].GetString ()) == " success" &&
736
+ doc.HasMember (" Data" ) && doc[" Data" ].IsObject ()) {
737
+ const rapidjson::Value& dataVal = doc[" Data" ];
738
+ if (dataVal.IsObject ()) {
739
+ const auto & data = dataVal.GetObject ();
740
+ if (data.HasMember (" peerId" ) && data[" peerId" ].IsString ()) {
741
+ MGINFO (" IPFS Started with Peer ID: " << data[" peerId" ].GetString ());
742
+
743
+ if (boost::filesystem::exists (import_file_path)) {
744
+ boost::filesystem::remove (import_file_path);
745
+ }
808
746
747
+ std::thread progressThread ([&]() {
748
+ using boost::posix_time::ptime;
749
+ using boost::posix_time::microsec_clock;
750
+ using boost::posix_time::time_duration;
751
+ using boost::posix_time::to_tm;
752
+
753
+ while (downloadInProgress) {
754
+ if (boost::filesystem::exists (import_file_path)) {
755
+ std::uintmax_t size = boost::filesystem::file_size (import_file_path);
756
+
757
+ ptime now = microsec_clock::local_time ();
758
+ time_duration td = now.time_of_day ();
759
+ struct tm tm_now = to_tm (now);
760
+
761
+ std::ostringstream time_ss;
762
+ time_ss << std::put_time (&tm_now, " %Y-%m-%d %H:%M:%S" )
763
+ << ' .' << std::setw (3 ) << std::setfill (' 0' ) << td.total_milliseconds () % 1000 ;
764
+
765
+ std::ostringstream oss;
766
+ oss << time_ss.str () << " I Downloaded: " << (size / (1024 * 1024 )) << " MB" ;
767
+
768
+ std::cout << " \r " << oss.str () << std::flush;
769
+ }
770
+
771
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
772
+ }
773
+ });
774
+
775
+ MGINFO (" Downloading blockchain from IPFS, this might take a few minutes.." );
776
+
777
+ const std::string getCid = " /ipns/blockchain.raw.scala.network" ;
778
+ std::string downloadResult = Get ((char *)getCid.c_str (), (char *)import_file_path.c_str (), true );
779
+ downloadInProgress = false ;
780
+ progressThread.join ();
781
+
782
+ rapidjson::Document dlDoc;
783
+ if (dlDoc.Parse (downloadResult.c_str ()).HasParseError ()) {
784
+ MGINFO (" Download result parse error" );
785
+ return 0 ;
786
+ }
787
+
788
+ if (dlDoc.HasMember (" Status" ) && dlDoc[" Status" ].IsString () &&
789
+ std::string (dlDoc[" Status" ].GetString ()) == " success" ) {
790
+ MGINFO (" Blockchain downloaded from IPFS" );
791
+ } else {
792
+ MGINFO (" Blockchain download failed" );
793
+ }
794
+
795
+ } else {
796
+ fail = true ;
797
+ }
798
+ }
799
+ } else {
800
+ fail = true ;
801
+ }
802
+
803
+ if (fail) {
804
+ MGINFO (" IPFS failed to initialize, exiting!" );
805
+ return 0 ;
806
+ }
807
+ }
808
+ #else
809
+ MGINFO (" IPFS import is not supported on Android" );
810
+ #endif
809
811
810
812
if (command_line::has_arg (vm, arg_ipfs_import))
811
813
{
0 commit comments