[Bf-extensions-cvs] [b4ca385a] master: io_coat3D: fixing exchange_folder.txt bug

Kalle-Samuli Riihikoski noreply at git.blender.org
Sun Nov 22 13:17:51 CET 2020


Commit: b4ca385ac92d1ab362a503760a0622b5774ea2cb
Author: Kalle-Samuli Riihikoski
Date:   Sun Nov 22 14:17:47 2020 +0200
Branches: master
https://developer.blender.org/rBAb4ca385ac92d1ab362a503760a0622b5774ea2cb

io_coat3D: fixing exchange_folder.txt bug

===================================================================

M	io_coat3D/__init__.py
M	io_coat3D/folders.py

===================================================================

diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index a5f28246..d766ffc7 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -45,6 +45,7 @@ import ntpath
 import re
 import shutil
 import pathlib
+import stat
 
 
 import time
@@ -266,8 +267,15 @@ class SCENE_OT_folder(bpy.types.Operator):
         coat3D = bpy.context.scene.coat3D
         if(os.path.isdir(coat3D.exchangeFolder)):
             foundExchangeFolder= True
-        else:
-            foundExchangeFolder = False
+            if(platform == 'win32' or platform == 'darwin'):
+                exchangeFile = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + '3DC2Blender' 
+            else:
+                exchangeFile = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + '3DC2Blender' 
+           
+            if(coat3D.exchangeFolder.rfind('Exchange') >= 0):
+                file = open(exchangeFile, 'w')
+                file.write(coat3D.exchangeFolder)
+                file.close()
 
         return {'FINISHED'}
 
diff --git a/io_coat3D/folders.py b/io_coat3D/folders.py
index b0594786..36471b98 100644
--- a/io_coat3D/folders.py
+++ b/io_coat3D/folders.py
@@ -14,26 +14,30 @@ def InitFolders():
     # 1. #################################################################
 
     if(platform == 'win32' or platform == 'darwin'):
-        exchangeFile = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'Exchange_folder.txt'
+        DC2Folder = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' 
     else:
-        exchangeFile = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + 'Exchange_folder.txt'
-    if(os.path.isfile(exchangeFile)):
-        folderPath = ''
+        DC2Folder = os.path.expanduser("~") + os.sep + '3DC2Blender' 
+    
+    exchangeFolderFile = DC2Folder + os.sep + 'Exchange_folder.txt'
 
-        folderPathh = open(exchangeFile)
-        for line in folderPathh:
-            folderPath = line
+    if(not os.path.isdir(DC2Folder)):
+        os.mkdir(DC2Folder)
+    
+    if(not os.path.isfile(exchangeFolderFile)):
+        file = open(exchangeFolderFile, 'w')
+        file.close()
+    else:
+        savedExchangePath = ''
+        folderPath = open(exchangeFolderFile)
+        
+        for line in folderPath:
+            savedExchangePath = line
             break
-        folderPathh.close()
+        folderPath.close()
 
-        if(os.path.isdir(os.path.abspath(folderPath)) and folderPath.rfind('Exchange') >= 0):
-            coat3D.exchangeFolder = folderPath
+        if(os.path.isdir(os.path.abspath(savedExchangePath)) and savedExchangePath.rfind('Exchange') >= 0):
+            coat3D.exchangeFolder = savedExchangePath
             return True, coat3D.exchangeFolder
-    else:
-        try:
-            os.makedirs(os.path.dirname(exchangeFile))
-        except:
-            pass
 
 
     # 2. #################################################################
@@ -50,7 +54,7 @@ def InitFolders():
         Blender_folder = ("%s%sBlender"%(exchangeFolder,os.sep))
 
         if(not(os.path.isdir(Blender_folder))):
-            os.makedirs(Blender_folder)
+            os.makedirs(Blender_folder, mode = 0o666)
             Blender_folder1 = os.path.join(Blender_folder,"run.txt")
             file = open(Blender_folder1, "w")
             file.close()
@@ -101,13 +105,13 @@ def set_working_folders():
         else:
             folder_objects = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'ApplinkObjects'
             if(not(os.path.isdir(folder_objects))):
-                os.makedirs(folder_objects)
+                os.makedirs(folder_objects, mode = 0o666)
     else:
         if (coat3D.defaultfolder != '' and os.path.isdir(coat3D.defaultfolder)):
             return coat3D.defaultfolder
         else:
             folder_objects = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + 'ApplinkObjects'
             if(not(os.path.isdir(folder_objects))):
-                os.makedirs(folder_objects)
+                os.makedirs(folder_objects, mode = 0o666)
 
     return folder_objects



More information about the Bf-extensions-cvs mailing list