From 8a6763af48a243ad3c7e04adfd6a2520d119adac Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期三, 28 六月 2023 18:05:25 +0800
Subject: [PATCH] Merge branch 'wjc' into hxb

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java |  184 +++++++++++++++++++++++++---------------------
 1 files changed, 100 insertions(+), 84 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
index 368ad9f..5b2ddd3 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
@@ -2,7 +2,7 @@
 
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.text.TextUtils;
+import android.os.Environment;
 import android.util.Log;
 
 import com.hdl.photovoltaic.HDLApp;
@@ -13,7 +13,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.IOException;
 
 /**
  * 鏂囦欢鎿嶄綔鐨勯�昏緫
@@ -48,56 +47,58 @@
     private String getHomeId() {
         return UserConfigManage.getInstance().getHomeId();
     }
+    //region    ---------root璺緞-----------
 
     /**
      * 鑾峰彇鎵嬫満鍐呴儴瀛樺偍鏂囦欢璺緞
      */
     private String getAPPInternalStoreFilesPath() {
-        return HDLApp.getInstance().getFilesDir().getAbsolutePath();
+        return HDLApp.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getPath();
     }
 
     /**
      * 鑾峰彇瀛樻斁鏂囦欢銆愮敤鎴枫�戞牴璺緞
      */
-    public String getUserFilesPath() {
-        return HDLApp.getInstance().getFilesDir().getAbsolutePath() + getUserId();
+    public String getCurrentUserRootPath() {
+        return getAPPInternalStoreFilesPath() + "/" + getUserId();
     }
 
     /**
      * 鑾峰彇瀛樻斁鏂囦欢銆愪綇瀹呫�戞牴璺緞
      */
-    public String getHomeFilesPath() {
-        return HDLApp.getInstance().getFilesDir().getAbsolutePath() + getUserId() + "/home";
+    public String getCurrentHomeRootPath() {
+        return getAPPInternalStoreFilesPath() + "/" + getUserId() + "/home";
     }
 
     /**
-     * 浣忓畢鍚嶇О
+     * 浣忓畢鏂囦欢鍚嶇О
      *
      * @return -
      */
-    public String getHomeFileName() {
-        return getHomeId() + ".json";
+    public String getCurrentHomeFileName() {
+        return "/" + getHomeId() + ".json";
     }
 
+
     /**
-     * 鍒涘缓鏂囦欢
-     *
-     * @param fullPath 鍏ㄨ矾寰�
-     * @return -
+     * 鑾峰彇褰撳墠浣忓畢鏂囦欢鍏ㄨ矾寰�
      */
-    public boolean createFile(String fullPath) {
-        try {
-            File file = new File(fullPath);
-            if (!file.exists()) {
-                boolean succeed = file.createNewFile();
-                HdlLogLogic.print("鍒涘缓鏂囦欢==" + succeed);
-                return succeed;
-            }
-            return true;
-        } catch (Exception e) {
-            HdlLogLogic.print("鍒涘缓鏂囦欢澶辫触==" + e.getMessage());
-            return false;
-        }
+    public String getCurrentHomeFilesFullPath() {
+        return getCurrentHomeRootPath() + getCurrentHomeFileName();
+    }
+
+    //endregion
+
+    //region    ---------銆愭枃浠跺す銆戞搷浣�-----------
+
+    /**
+     * 棰勫垱寤烘枃浠跺す
+     */
+    public void createDirectory() {
+        //瀛樻斁鐢ㄦ埛淇℃伅
+        this.createFileDir(this.getCurrentUserRootPath());
+        //瀛樻斁浣忓畢淇℃伅
+        this.createFileDir(this.getCurrentHomeRootPath());
     }
 
     /**
@@ -116,11 +117,75 @@
             }
             return true;
         } catch (Exception e) {
-            HdlLogLogic.print("鍒涘缓鏂囦欢澶瑰け璐�==" + e.getMessage());
+            HdlLogLogic.print("鍒涘缓鏂囦欢澶规湁寮傚父==" + e.getMessage());
             return false;
         }
     }
 
+
+    /**
+     * 鍒犻櫎鏂囦欢澶�
+     *
+     * @param fullPath 鍏ㄨ矾寰�
+     */
+    public void deleteDirectory(String fullPath) {
+        try {
+            File file = new File(fullPath);
+            if (file.isDirectory()) {
+                boolean succeed = file.delete();
+                HdlLogLogic.print("鍒犻櫎鏂囦欢澶�==" + succeed);
+            }
+        } catch (Exception e) {
+            HdlLogLogic.print("鍒犻櫎鏂囦欢澶规湁寮傚父==" + e.getMessage());
+        }
+
+    }
+    //endregion
+
+    //region    ---------銆愭枃浠躲�戞搷浣�-----------
+
+    /**
+     * 鍒涘缓鏂囦欢
+     *
+     * @param fullPath 鍏ㄨ矾寰�
+     * @return -
+     */
+    public boolean createFile(String fullPath) {
+        try {
+            File file = new File(fullPath);
+            if (!file.exists()) {
+                boolean succeed = file.createNewFile();
+                HdlLogLogic.print("鍒涘缓鏂囦欢==" + succeed);
+                return succeed;
+            }
+            return true;
+        } catch (Exception e) {
+            HdlLogLogic.print("鍒涘缓鏂囦欢鏈夊紓甯�==" + e.getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 鍒犻櫎鏂囦欢
+     *
+     * @param fullPath 鍏ㄨ矾寰�
+     * @return -
+     */
+    public boolean deleteFile(String fullPath) {
+        try {
+            File file = new File(fullPath);
+            if (file.exists()) {
+                boolean succeed = file.delete();
+                HdlLogLogic.print("鍒犻櫎鏂囦欢==" + succeed);
+                return succeed;
+            }
+            return true;
+        } catch (Exception e) {
+            HdlLogLogic.print("鍒犻櫎鏂囦欢鏈夊紓甯�==" + e.getMessage());
+            return false;
+        }
+
+    }
 
     /**
      * 鍐欏叆鏂囦欢
@@ -141,8 +206,9 @@
             d.write(data.getBytes());
             d.flush();
             d.close();
-        } catch (IOException e) {
-            e.printStackTrace();
+            HdlLogLogic.print("鍐欏叆鏂囦欢鎴愬姛==" + fullPath);
+        } catch (Exception e) {
+            HdlLogLogic.print("鍐欏叆鏂囦欢鏈夊紓甯�==" + e.getMessage());
         }
 
     }
@@ -169,15 +235,16 @@
             byte[] bytes = new byte[fis.available()];
             fis.read(bytes);
             fis.close();
+            HdlLogLogic.print("璇诲彇鏂囦欢鎴愬姛==" + filepath);
             fileContent = new String(bytes);
             return fileContent;
         } catch (Exception e1) {
-            e1.printStackTrace();
-            Log.d(TAG, "Error: Input File not find!");
+            HdlLogLogic.print("璇诲彇鏂囦欢鏈夊紓甯�==" + e1.getMessage());
             return "";
         }
 
     }
+    //endregion
 
     /**
      * 鎶婁綅鍥炬暟鎹繚瀛樺埌鎸囧畾璺緞鐨勫浘鐗囨枃浠�
@@ -197,6 +264,7 @@
         } catch (Exception e) {
         }
     }
+    //</editor-fold>
 
     /**
      * 浠庢寚瀹氳矾寰勭殑鍥剧墖鏂囦欢涓鍙栦綅鍥炬暟鎹�
@@ -215,57 +283,5 @@
         return null;
     }
 
-    /**
-     * 棰勫垱寤烘枃浠跺す
-     */
-    public void createDirectory() {
-        //鐢ㄦ埛淇℃伅
-        this.createFileDir(this.getUserFilesPath());
-        //浣忓畢淇℃伅
-        this.createFileDir(this.getHomeFilesPath());
-    }
 
-    /**
-     * 鍒犻櫎鏂囦欢
-     *
-     * @param fullPath 鍏ㄨ矾寰�
-     * @return -
-     */
-    public boolean deleteFile(String fullPath) {
-        try {
-            File file = new File(fullPath);
-            if (file.exists() || file.isDirectory()) {
-                boolean succeed = file.delete();
-                HdlLogLogic.print("鍒犻櫎鏂囦欢==" + succeed);
-                return succeed;
-            }
-            return true;
-        } catch (Exception e) {
-            HdlLogLogic.print("鍒犻櫎鏂囦欢鏈夊紓甯�==" + e.getMessage());
-            return false;
-        }
-
-    }
-
-    /**
-     * 鍒犻櫎鏂囦欢澶�
-     *
-     * @param fullPath 鍏ㄨ矾寰�
-     * @return -
-     */
-    public boolean deleteDirectory(String fullPath) {
-        try {
-            File file = new File(fullPath);
-            if (file.isDirectory()) {
-                boolean succeed = file.delete();
-                HdlLogLogic.print("鍒犻櫎鏂囦欢澶�==" + succeed);
-                return succeed;
-            }
-            return true;
-        } catch (Exception e) {
-            HdlLogLogic.print("鍒犻櫎鏂囦欢澶规湁寮傚父==" + e.getMessage());
-            return false;
-        }
-
-    }
 }

--
Gitblit v1.8.0