سؤال

عند إلغاء تثبيت التطبيق الخاص بي ، أود أن تكوين Wix برنامج الإعداد إزالة كافة الملفات التي تمت إضافتها بعد التثبيت الأصلي.يبدو أن إلغاء التثبيت يزيل فقط الدلائل والملفات التي تم تثبيتها في الأصل من MSI ويترك كل شيء آخر التي تم إضافتها لاحقا في مجلد التطبيق.وبعبارة أخرى, أود أن تطهير الدليل عند إلغاء تثبيت.كيف أفعل ذلك ؟

هل كانت مفيدة؟

المحلول

استخدام RemoveFile عنصر مع="إلغاء".هنا مثال:

<Directory Id="CommonAppDataFolder" Name="CommonAppDataFolder">
  <Directory Id="MyAppFolder" Name="My">
    <Component Id="MyAppFolder" Guid="*">
      <CreateFolder />
      <RemoveFile Id="PurgeAppFolder" Name="*.*" On="uninstall" />
    </Component>
  </Directory>
</Directory>

التحديث

لم يعمل 100%.فإنه إزالة الملفات غير أن أيا من أدلة إضافية - تلك التي تم إنشاؤها بعد تثبيت - أزيلت.أي أفكار عن ذلك ؟ – pribeiro

للأسف Windows Installer لا يدعم حذف الدلائل مع الدلائل.في هذه الحالة عليك أن تلجأ إلى إجراء مخصص.أو إذا كنت تعرف ما الفرعية هي إنشاء مجموعة من RemoveFolder و RemoveFile العناصر.

نصائح أخرى

استخدام RemoveFolderEx عنصر من Util التمديد في WiX.
مع هذا النهج ، كل الدلائل أيضا إزالة (بدلا من باستخدام RemoveFile العنصر مباشرة).هذا العنصر يضيف المؤقتة الصفوف RemoveFile و RemoveFolder الجدول في قاعدة بيانات MSI.

للقيام بذلك, أنا ببساطة إنشاء إجراء مخصص ليتم استدعاؤها على إلغاء التثبيت.

عن WiX رمز سوف تبدو مثل هذا:

<Binary Id="InstallUtil" src="InstallUtilLib.dll" />

<CustomAction Id="DIRCA_TARGETDIR" Return="check" Execute="firstSequence" Property="TARGETDIR" Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" />
<CustomAction Id="Uninstall" BinaryKey="InstallUtil" DllEntry="ManagedInstall" Execute="deferred" />
<CustomAction Id="UninstallSetProp" Property="Uninstall" Value="/installtype=notransaction /action=uninstall /LogFile= /targetDir=&quot;[TARGETDIR]\Bin&quot; &quot;[#InstallerCustomActionsDLL]&quot; &quot;[#InstallerCustomActionsDLLCONFIG]&quot;" />

<Directory Id="BinFolder" Name="Bin" >
    <Component Id="InstallerCustomActions" Guid="*">
        <File Id="InstallerCustomActionsDLL" Name="SetupCA.dll" LongName="InstallerCustomActions.dll" src="InstallerCustomActions.dll" Vital="yes" KeyPath="yes" DiskId="1" Compressed="no" />
        <File Id="InstallerCustomActionsDLLCONFIG" Name="SetupCA.con" LongName="InstallerCustomActions.dll.Config" src="InstallerCustomActions.dll.Config" Vital="yes" DiskId="1" />
    </Component>
</Directory>

<Feature Id="Complete" Level="1" ConfigurableDirectory="TARGETDIR">
    <ComponentRef Id="InstallerCustomActions" />
</Feature>

<InstallExecuteSequence>
    <Custom Action="UninstallSetProp" After="MsiUnpublishAssemblies">$InstallerCustomActions=2</Custom>
    <Custom Action="Uninstall" After="UninstallSetProp">$InstallerCustomActions=2</Custom>
</InstallExecuteSequence>

رمز OnBeforeUninstall الأسلوب في InstallerCustomActions.DLL سوف تبدو مثل هذا (في VB).

Protected Overrides Sub OnBeforeUninstall(ByVal savedState As System.Collections.IDictionary)
    MyBase.OnBeforeUninstall(savedState)

    Try
        Dim CommonAppData As String = Me.Context.Parameters("CommonAppData")
        If CommonAppData.StartsWith("\") And Not CommonAppData.StartsWith("\\") Then
            CommonAppData = "\" + CommonAppData
        End If
        Dim targetDir As String = Me.Context.Parameters("targetDir")
        If targetDir.StartsWith("\") And Not targetDir.StartsWith("\\") Then
            targetDir = "\" + targetDir
        End If

        DeleteFile("<filename.extension>", targetDir) 'delete from bin directory
        DeleteDirectory("*.*", "<DirectoryName>") 'delete any extra directories created by program
    Catch
    End Try
End Sub

Private Sub DeleteFile(ByVal searchPattern As String, ByVal deleteDir As String)
    Try
        For Each fileName As String In Directory.GetFiles(deleteDir, searchPattern)
            File.Delete(fileName)
        Next
    Catch
    End Try
End Sub

Private Sub DeleteDirectory(ByVal searchPattern As String, ByVal deleteDir As String)
    Try
        For Each dirName As String In Directory.GetDirectories(deleteDir, searchPattern)
            Directory.Delete(dirName)
        Next
    Catch
    End Try
End Sub

هنا الاختلاف على @tronda اقتراح.أنا حذف الملف "install.سجل" أن يحصل خلقت من جانب آخر مخصص العمل خلال إلغاء:

<Product>
    <CustomAction Id="Cleanup_logfile" Directory="INSTALLFOLDER"
    ExeCommand="cmd /C &quot;del install.log&quot;"
    Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

    <InstallExecuteSequence>
      <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
        REMOVE="ALL"
      </Custom>
    </InstallExecuteSequence>
</Product>

بقدر ما أفهم أنا لا يمكن استخدام "RemoveFile" لأن هذا الملف تم إنشاؤه بعد التثبيت ، وليس جزءا من مكونات المجموعة.

لا WIX الخبراء لكن هل ممكن (أبسط؟) حل هذا إلى تشغيل هادئة تنفيذ إجراء مخصص الذي هو جزء من المدمج في امتداد من WIX?

يمكن تشغيل rmdir MS DOS مع /S /Q الخيارات.

<Binary Id="CommandPrompt" SourceFile="C:\Windows\System32\cmd.exe" />

و إجراء مخصص يقوم بعمل بسيط:

<CustomAction Id="DeleteFolder" BinaryKey="CommandPrompt" 
              ExeCommand='/c rmdir /S /Q "[CommonAppDataFolder]MyAppFolder\PurgeAppFolder"' 
              Execute="immediate" Return="check" />

ثم سيكون لديك لتعديل InstallExecuteSequence كما وثقت العديد من الأماكن.

تحديث: كان لديه مشاكل مع هذا النهج.انتهى صنع مهمة مخصصة بدلا من ذلك, ولكن لا تزال ترى هذا حلا قابلا للتطبيق ، ولكن من دون الحصول على تفاصيل العمل.

وهذا من شأنه أن يكون أكثر إجابة كاملة عن @بافل اقتراح بالنسبة لي انها تعمل 100%:

<Fragment Id="FolderUninstall">
    <?define RegDir="SYSTEM\ControlSet001\services\[Manufacturer]:[ProductName]"?>
    <?define RegValueName="InstallDir"?>
    <Property Id="INSTALLFOLDER">
        <RegistrySearch Root="HKLM" Key="$(var.RegDir)" Type="raw" 
                  Id="APPLICATIONFOLDER_REGSEARCH" Name="$(var.RegValueName)" />
    </Property>

    <DirectoryRef Id='INSTALLFOLDER'>
        <Component Id="UninstallFolder" Guid="*">
            <CreateFolder Directory="INSTALLFOLDER"/>
            <util:RemoveFolderEx Property="INSTALLFOLDER" On="uninstall"/>
            <RemoveFolder Id="INSTALLFOLDER" On="uninstall"/>
            <RegistryValue Root="HKLM" Key="$(var.RegDir)" Name="$(var.RegValueName)" 
                    Type="string" Value="[INSTALLFOLDER]" KeyPath="yes"/>
        </Component>
    </DirectoryRef>
</Fragment>

و تحت منتوج عنصر:

<Feature Id="Uninstall">
    <ComponentRef Id="UninstallFolder" Primary="yes"/>
</Feature>

هذا النهج تعيين قيمة التسجيل المطلوب مسار المجلد المراد حذفه على إلغاء التثبيت.في النهاية كل INSTALLFOLDER التسجيل مجلد يتم إزالتها من النظام.علما أن الطريق إلى التسجيل في خلية أخرى وغيرها من المواقع.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top