| 3644 | if (dbver == "1215") |
| 3645 | { |
| 3646 | #ifdef USING_HDHOMERUN |
| 3647 | VERBOSE(VB_IMPORTANT, "In 1215 upg (HDhomerun tunerid change)"); |
| 3648 | |
| 3649 | // First discover all HDhomreun devices on the network |
| 3650 | // This will be cached and used to match up with the database query |
| 3651 | |
| 3652 | uint32_t target_ip = 0; // WILDCARD |
| 3653 | uint32_t device_type = HDHOMERUN_DEVICE_TYPE_TUNER; |
| 3654 | uint32_t device_id = HDHOMERUN_DEVICE_ID_WILDCARD; |
| 3655 | const int max_count = 50; |
| 3656 | hdhomerun_discover_device_t hdhr_device_list[max_count]; |
| 3657 | |
| 3658 | int hdhr_device_count = hdhomerun_discover_find_devices_custom( |
| 3659 | target_ip, |
| 3660 | device_type, |
| 3661 | device_id, |
| 3662 | hdhr_device_list, |
| 3663 | max_count); |
| 3664 | |
| 3665 | if (hdhr_device_count == -1) |
| 3666 | { |
| 3667 | // Can only check for existing devices |
| 3668 | VERBOSE(VB_IMPORTANT, "Error finding HDHomerun devices"); |
| 3669 | VERBOSE(VB_IMPORTANT, "All configured HDHomerun devices must be accessible"); |
| 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | MSqlQuery query(MSqlQuery::InitCon()); |
| 3674 | query.prepare("SELECT cardid, videodevice, dbox2_port " |
| 3675 | "FROM capturecard " |
| 3676 | "WHERE cardtype = 'HDHOMERUN' " |
| 3677 | "ORDER BY cardid"); |
| 3678 | bool ok = query.exec(); |
| 3679 | |
| 3680 | MSqlQuery query2(MSqlQuery::InitCon()); |
| 3681 | QRegExp newstyle = QRegExp("[0-9A-Z]{8}-[0-9]", false); |
| 3682 | QRegExp newwildcard = QRegExp("F{8}-[0-9]", false); // "FFFFFFFF-n" |
| 3683 | |
| 3684 | while (ok && query.next()) |
| 3685 | { |
| 3686 | uint cardid = query.value(0).toUInt(); |
| 3687 | QString device = query.value(1).toString(); |
| 3688 | uint tunerid = query.value(2).toUInt(); |
| 3689 | |
| 3690 | // First check if this is the new style already |
| 3691 | if (device.contains(newstyle) > 0) |
| 3692 | { |
| 3693 | QString new_device = ""; |
| 3694 | if (device.contains(newwildcard) > 0) // FFFFFFFF-1 |
| 3695 | { |
| 3696 | // Must convert to an actual HDHR |
| 3697 | // Use the first HDHR found. |
| 3698 | |
| 3699 | QString new_device_id = QString("%1").arg(hdhr_device_list[0].device_id, 8, 16); |
| 3700 | new_device = device; |
| 3701 | new_device.replace("ffffffff", new_device_id, false); |
| 3702 | } else if (device.upper() == device) |
| 3703 | VERBOSE(VB_GENERAL, QString("Retaining card %1: HDhomerun %2") |
| 3704 | .arg(cardid).arg(device)); |
| 3705 | else |
| 3706 | { |
| 3707 | // Convert to upper case |
| 3708 | new_device = device; |
| 3709 | } |
| 3710 | |
| 3711 | if (new_device.length() > 0) |
| 3712 | { |
| 3713 | QString updatequery = QString("UPDATE capturecard SET videodevice = '%1' " |
| 3714 | "WHERE cardid = %2;") |
| 3715 | .arg(new_device.upper()) |
| 3716 | .arg(cardid); |
| 3717 | VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 to %3") |
| 3718 | .arg(cardid).arg(device).arg(new_device.upper())); |
| 3719 | |
| 3720 | if (!query2.exec(updatequery)) |
| 3721 | { |
| 3722 | QString msg = |
| 3723 | QString("DB Error (Performing database upgrade): \n" |
| 3724 | "Query was: %1 \nError was: %2") |
| 3725 | .arg(updatequery) |
| 3726 | .arg(MythContext::DBErrorMessage(query2.lastError())); |
| 3727 | VERBOSE(VB_IMPORTANT, msg); |
| 3728 | ok = false; |
| 3729 | } |
| 3730 | } |
| 3731 | } |
| 3732 | else |
| 3733 | { |
| 3734 | // change from device, tuner to device-tuner |
| 3735 | // i.e.: AABBCCDD, 1 -> AABBCCDD-1 |
| 3736 | // If device is xxxxxxxx then use it directly |
| 3737 | // If device is FFFFFFFF then try to discover the HDHR to get the actual value |
| 3738 | // If device is x.x.x.x (ip address) then try to discover the HDHR to get the actual value |
| 3739 | |
| 3740 | bool valid; |
| 3741 | uint device_id = device.toUInt(&valid, 16); |
| 3742 | |
| 3743 | QString new_device = ""; |
| 3744 | if (valid && device_id != HDHOMERUN_DEVICE_ID_WILDCARD |
| 3745 | && hdhomerun_discover_validate_device_id(device_id)) |
| 3746 | { |
| 3747 | // Valid, non-wildcard device id |
| 3748 | // Update it to "xxxxxxxx-#" |
| 3749 | new_device = QString("%1-%2").arg(device).arg(tunerid); |
| 3750 | |
| 3751 | } |
| 3752 | else if (valid && device_id == HDHOMERUN_DEVICE_ID_WILDCARD) |
| 3753 | { |
| 3754 | // Use the first HDHR found. It should be the only one if this |
| 3755 | // worked before. |
| 3756 | |
| 3757 | new_device = QString("%1-%2") |
| 3758 | .arg(hdhr_device_list[0].device_id, 8, 16) |
| 3759 | .arg(tunerid); |
| 3760 | } |
| 3761 | else |
| 3762 | { |
| 3763 | |
| 3764 | // Check for IP address; |
| 3765 | |
| 3766 | struct in_addr address; |
| 3767 | uint tmp_device_ip; |
| 3768 | if (inet_aton(device, &address)) |
| 3769 | { |
| 3770 | tmp_device_ip = ntohl(address.s_addr); |
| 3771 | int i; |
| 3772 | for (i = 0; i < hdhr_device_count; i++) |
| 3773 | { |
| 3774 | if (tmp_device_ip == hdhr_device_list[i].ip_addr) |
| 3775 | { |
| 3776 | new_device = QString("%1-%2") |
| 3777 | .arg(hdhr_device_list[1].device_id, 8, 16) |
| 3778 | .arg(tunerid); |
| 3779 | break; |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | // If we identified the HDhomerun device, update it. |
| 3786 | // Otherwise delete it |
| 3787 | |
| 3788 | QString updatequery; |
| 3789 | if (new_device.length() > 0) |
| 3790 | { |
| 3791 | updatequery = QString("UPDATE capturecard SET videodevice = '%1', dbox2_port = 31338 " |
| 3792 | "WHERE cardid = %2;") |
| 3793 | .arg(new_device.upper()) |
| 3794 | .arg(cardid); |
| 3795 | VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 tuner %3 to %4") |
| 3796 | .arg(cardid).arg(device) |
| 3797 | .arg(tunerid).arg(new_device.upper())); |
| 3798 | } |
| 3799 | else |
| 3800 | { |
| 3801 | updatequery = QString("DELETE FROM capturecard " |
| 3802 | "WHERE cardid = %1;") |
| 3803 | .arg(cardid); |
| 3804 | VERBOSE(VB_IMPORTANT, QString("Couldn't find card %1: HDHomerun %2 tuner %3 - deleting") |
| 3805 | .arg(cardid).arg(device).arg(tunerid)); |
| 3806 | } |
| 3807 | |
| 3808 | if (!query2.exec(updatequery)) |
| 3809 | { |
| 3810 | QString msg = |
| 3811 | QString("DB Error (Performing database upgrade): \n" |
| 3812 | "Query was: %1 \nError was: %2") |
| 3813 | .arg(updatequery) |
| 3814 | .arg(MythContext::DBErrorMessage(query2.lastError())); |
| 3815 | VERBOSE(VB_IMPORTANT, msg); |
| 3816 | ok = false; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | #endif // USING_HDHOMERUN |
| 3821 | const QString updates[] = { "" }; |
| 3822 | |
| 3823 | if (!performActualUpdate(updates, "1216", dbver)) |
| 3824 | return false; |
| 3825 | VERBOSE(VB_IMPORTANT, "DBCheck: done with HDhomerun upgrade"); |
| 3826 | } |