Skip to content

Bugfix/itunes backup #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Mixin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@
9427D52725E0EB5B00B1EF0E /* PlaylistItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9427D52625E0EB5B00B1EF0E /* PlaylistItem.swift */; };
942F829825DD56E3004F913B /* opusenc_set_bitrate.c in Sources */ = {isa = PBXBuildFile; fileRef = 942F829725DD56E3004F913B /* opusenc_set_bitrate.c */; };
9430F9C525E38AB5001CCA2F /* MessageDAO+PlaylistItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9430F9C425E38AB5001CCA2F /* MessageDAO+PlaylistItem.swift */; };
943673342715B0C900706F28 /* iTunesBackupDiagnosticViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943673332715B0C900706F28 /* iTunesBackupDiagnosticViewController.swift */; };
943673362715B0E100706F28 /* iTunesBackupDiagnosticView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 943673352715B0E100706F28 /* iTunesBackupDiagnosticView.xib */; };
9438252725EE697300709B7D /* CacheableAssetFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9438252625EE697300709B7D /* CacheableAssetFileManager.swift */; };
94438D57252DAD73005760AF /* Clip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94438D56252DAD73005760AF /* Clip.swift */; };
944C656125D9BA0A008BDDD3 /* OggOpusWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944C656025D9BA0A008BDDD3 /* OggOpusWriter.swift */; };
Expand Down Expand Up @@ -1583,6 +1585,8 @@
942F829625DD56E3004F913B /* opusenc_set_bitrate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = opusenc_set_bitrate.h; sourceTree = "<group>"; };
942F829725DD56E3004F913B /* opusenc_set_bitrate.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = opusenc_set_bitrate.c; sourceTree = "<group>"; };
9430F9C425E38AB5001CCA2F /* MessageDAO+PlaylistItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageDAO+PlaylistItem.swift"; sourceTree = "<group>"; };
943673332715B0C900706F28 /* iTunesBackupDiagnosticViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iTunesBackupDiagnosticViewController.swift; sourceTree = "<group>"; };
943673352715B0E100706F28 /* iTunesBackupDiagnosticView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = iTunesBackupDiagnosticView.xib; sourceTree = "<group>"; };
9438252625EE697300709B7D /* CacheableAssetFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheableAssetFileManager.swift; sourceTree = "<group>"; };
94438D56252DAD73005760AF /* Clip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clip.swift; sourceTree = "<group>"; };
944C656025D9BA0A008BDDD3 /* OggOpusWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OggOpusWriter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2640,6 +2644,8 @@
94B8D184266E37ED00F43CBB /* DiagnoseViewController.swift */,
94B8D188266E41D300F43CBB /* DatabaseDiagnosticView.xib */,
94B8D187266E41D300F43CBB /* DatabaseDiagnosticViewController.swift */,
943673352715B0E100706F28 /* iTunesBackupDiagnosticView.xib */,
943673332715B0C900706F28 /* iTunesBackupDiagnosticViewController.swift */,
);
path = Diagnose;
sourceTree = "<group>";
Expand Down Expand Up @@ -3870,6 +3876,7 @@
7B2A115D22C1EAC900AD029C /* GalleryVideoControlView.xib in Resources */,
7B9A18162428932A00187693 /* PageControlView.xib in Resources */,
DF2A0D952295721200CA0280 /* AddressView.xib in Resources */,
943673362715B0E100706F28 /* iTunesBackupDiagnosticView.xib in Resources */,
7BCEAA782350A29000F07635 /* SharedMediaDataCell.xib in Resources */,
E0BC7BB7238FADE000E3EF2C /* MyFavoriteAppProfileMenuItemView.xib in Resources */,
7B81BF2922893F8B00266A77 /* GroupParticipantCell.xib in Resources */,
Expand Down Expand Up @@ -4299,6 +4306,7 @@
7B88655920AC330D002D15E4 /* PhotoRepresentableMessageViewModel.swift in Sources */,
7BBD2792221E7C9E0047E7D1 /* CheckmarkView.swift in Sources */,
7BB8E2D124529E910098B1E8 /* AppearanceSettingsViewController.swift in Sources */,
943673342715B0C900706F28 /* iTunesBackupDiagnosticViewController.swift in Sources */,
7B1ABB07211968D1009FAA6C /* StickersViewController.swift in Sources */,
7B8A6A742456E0EC00ADC9EB /* SharedMediaPostCell.swift in Sources */,
DF2EB15C23F93870005E5A4F /* CleanUpUnusedAttachmentJob.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Mixin/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,8 @@
// Diagnose
"diagnose_database" = "Database Diagnostics";
"diagnose_database_description" = "Database Diagnostics";
"diagnose_backup_restore" = "Backup & Restore";
"diagnose_copy_output" = "Copy Output";

// Notifications
"notification_reply" = "Reply";
Expand Down
2 changes: 2 additions & 0 deletions Mixin/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@
// Diagnose
"diagnose_warning" = "⚠️请在Mixin团队指导下使用";
"diagnose_database_access" = "数据库访问";
"diagnose_backup_restore" = "备份恢复";
"diagnose_copy_output" = "复制结果";

"report_title"="给开发人员发送聊天日志?";
"report_button"="把日志发给开发者";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class DiagnoseViewController: SettingsTableViewController {
private let dataSource = SettingsDataSource(sections: [
SettingsSection(header: R.string.localizable.diagnose_warning(), rows: [
SettingsRow(title: R.string.localizable.diagnose_database_access(), accessory: .disclosure),
]),
SettingsSection(rows: [
SettingsRow(title: R.string.localizable.diagnose_backup_restore(), accessory: .disclosure),
])
])

Expand All @@ -19,9 +22,19 @@ class DiagnoseViewController: SettingsTableViewController {
extension DiagnoseViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let container = ContainerViewController.instance(viewController: DatabaseDiagnosticViewController(),
title: R.string.localizable.diagnose_database_access())
navigationController?.pushViewController(container, animated: true)
tableView.deselectRow(at: indexPath, animated: true)
switch indexPath.section {
case 0:
let container = ContainerViewController.instance(viewController: DatabaseDiagnosticViewController(),
title: R.string.localizable.diagnose_database_access())
navigationController?.pushViewController(container, animated: true)
case 1:
let container = ContainerViewController.instance(viewController: iTunesBackupDiagnosticViewController(),
title: R.string.localizable.diagnose_backup_restore())
navigationController?.pushViewController(container, animated: true)
default:
break
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="iTunesBackupDiagnosticViewController" customModule="Mixin" customModuleProvider="target">
<connections>
<outlet property="diagnoseButton" destination="l5s-Nx-gT0" id="fOE-bm-kcr"/>
<outlet property="outputTextView" destination="lpo-i1-Qoz" id="rzk-4T-fXV"/>
<outlet property="view" destination="iN0-l3-epB" id="VdX-Ra-F9D"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qJa-lX-97k">
<rect key="frame" x="20" y="44" width="374" height="64"/>
<subviews>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="l5s-Nx-gT0" customClass="BusyButton" customModule="Mixin" customModuleProvider="target">
<rect key="frame" x="0.0" y="8" width="374" height="56"/>
<color key="backgroundColor" name="background_secondary"/>
<constraints>
<constraint firstAttribute="height" constant="56" id="3gf-la-F77"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="开始检测"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="diagnose:" destination="-1" eventType="touchUpInside" id="kW7-6q-xTD"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstItem="l5s-Nx-gT0" firstAttribute="top" secondItem="qJa-lX-97k" secondAttribute="top" constant="8" id="Ejw-eL-pd9"/>
<constraint firstItem="l5s-Nx-gT0" firstAttribute="leading" secondItem="qJa-lX-97k" secondAttribute="leading" id="RvS-tQ-HIw"/>
<constraint firstAttribute="trailing" secondItem="l5s-Nx-gT0" secondAttribute="trailing" id="SnK-vD-a9e"/>
<constraint firstAttribute="bottom" secondItem="l5s-Nx-gT0" secondAttribute="bottom" id="bW3-a3-jF1"/>
</constraints>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="lpo-i1-Qoz">
<rect key="frame" x="0.0" y="128" width="414" height="768"/>
<color key="backgroundColor" name="background"/>
<color key="textColor" systemColor="labelColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstItem="qJa-lX-97k" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="CSt-Bn-hsK"/>
<constraint firstItem="lpo-i1-Qoz" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="D3i-CT-2Hu"/>
<constraint firstItem="qJa-lX-97k" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="GY7-SH-ib5"/>
<constraint firstItem="lpo-i1-Qoz" firstAttribute="top" secondItem="qJa-lX-97k" secondAttribute="bottom" constant="20" id="RBe-uw-Ngg"/>
<constraint firstAttribute="trailing" secondItem="lpo-i1-Qoz" secondAttribute="trailing" id="Wv4-qf-glZ"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="qJa-lX-97k" secondAttribute="trailing" constant="20" id="pJO-mC-fcv"/>
<constraint firstAttribute="bottom" secondItem="lpo-i1-Qoz" secondAttribute="bottom" id="uFx-mq-p5O"/>
</constraints>
<point key="canvasLocation" x="137.68115942028987" y="153.34821428571428"/>
</view>
</objects>
<resources>
<namedColor name="background">
<color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<namedColor name="background_secondary">
<color red="0.96470588235294119" green="0.96862745098039216" blue="0.98039215686274506" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<systemColor name="labelColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import UIKit
import MixinServices

class iTunesBackupDiagnosticViewController: UIViewController {

@IBOutlet weak var diagnoseButton: BusyButton!
@IBOutlet weak var outputTextView: UITextView!

override func viewDidLoad() {
super.viewDidLoad()
outputTextView.contentInset.left = 20
outputTextView.contentInset.right = 20
container?.rightButton.isEnabled = true
}

@IBAction func diagnose(_ sender: Any) {
outputTextView.text = ""
diagnoseButton.isBusy = true
DispatchQueue.global().async {
defer {
DispatchQueue.main.async {
self.diagnoseButton.isBusy = false
}
}
let urls = [
AppGroupContainer.url,

AppGroupContainer.documentsUrl,

AppGroupContainer.signalDatabaseUrl,
AppGroupContainer.documentsUrl.appendingPathComponent("signal.db-wal", isDirectory: false),
AppGroupContainer.documentsUrl.appendingPathComponent("signal.db-shm", isDirectory: false),

AppGroupContainer.accountUrl,

AppGroupContainer.userDatabaseUrl,
AppGroupContainer.accountUrl.appendingPathComponent("mixin.db-wal", isDirectory: false),
AppGroupContainer.accountUrl.appendingPathComponent("mixin.db-shm", isDirectory: false),

AppGroupContainer.taskDatabaseUrl,
AppGroupContainer.accountUrl.appendingPathComponent("task.db-wal", isDirectory: false),
AppGroupContainer.accountUrl.appendingPathComponent("task.db-shm", isDirectory: false),

AttachmentContainer.url
]
for url in urls {
do {
let values = try url.resourceValues(forKeys: [.isExcludedFromBackupKey])
let isExcludedFromBackup = values.isExcludedFromBackup ?? true
if isExcludedFromBackup {
try (url as NSURL).setResourceValue(false, forKey: .isExcludedFromBackupKey)
self.output("⚠️ Fixed a non-backup URL: \(url)")
} else {
self.output("✅ Backup URL: \(url)")
}
} catch {
self.output("❌ Failed to manipulate URL: \(url), error: \(error)")
}
}

let enumerator = FileManager.default.enumerator(at: AttachmentContainer.url, includingPropertiesForKeys: [.isExcludedFromBackupKey]) { url, error in
self.output("❌ Enumeration error on URL: \(url), error: \(error)")
return true
}
guard let enumerator = enumerator else {
self.output("❌ Enumerator is nil")
return
}
var backupCount = 0
var fixedURLs: [URL] = []
var failedURLs: [(URL, Error)] = []
while let url = enumerator.nextObject() as? URL {
do {
let values = try url.resourceValues(forKeys: [.isExcludedFromBackupKey])
let isExcludedFromBackup = values.isExcludedFromBackup ?? true
if isExcludedFromBackup {
do {
try (url as NSURL).setResourceValue(false, forKey: .isExcludedFromBackupKey)
fixedURLs.append(url)
} catch {
failedURLs.append((url, error))
}
} else {
backupCount += 1
}
} catch {
failedURLs.append((url, error))
}
}
self.output("\nAttachment enumeration:\n✅ \(backupCount) files are OK\n")
for url in fixedURLs {
self.output("⚠️ Non-backup URL is fixed: \(url)")
}
for (url, error) in failedURLs {
self.output("❌ Failed to manipulate URL: \(url), error: \(error)")
}
}
}

private func output(_ text: String) {
DispatchQueue.main.async {
let newLine = text + "\n"
self.outputTextView.text.append(newLine)
}
}

}

extension iTunesBackupDiagnosticViewController: ContainerViewControllerDelegate {

func barRightButtonTappedAction() {
UIPasteboard.general.string = outputTextView.text
showAutoHiddenHud(style: .notification, text: R.string.localizable.toast_copied())
}

func textBarRightButton() -> String? {
R.string.localizable.diagnose_copy_output()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
public enum AppGroupContainer {

// In iOS, the value is nil when the group identifier is invalid.
static let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)!
public static let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)!

public static let documentsUrl: URL = {
let url = AppGroupContainer.url.appendingPathComponent("Documents", isDirectory: true)
Expand Down